Class MvnRepoLookup

java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.mvnrepo.MvnRepoLookup
All Implemented Interfaces:
ResourceProvider

public class MvnRepoLookup extends AbstractProvider

Depending on the request, this provider provides two types of resources.

  1. The artifacts to be resolved as resources of type MvnRepoDependency. The artifacts to be resolved are those added with resolve(java.lang.String...). Note that the result also includes the MvnRepoBoms added with bom(java.lang.String...).

  2. The resources of type MvnRepoLibraryJarFile that result from resolving the artifacts to be resolved.

The repositories used are those added with addRepositories(org.eclipse.aether.repository.RemoteRepository...). If no repositories are configured, the Maven Central repository is added automatically.

Resolving is performed using Maven Resolver (formerly Eclipse Aether) version 2.x. Dependencies are collected from the specified artifacts after evaluating their effective Maven models, including any imported BOMs. Version conflicts are resolved using a "highest wins" strategy, i.e. the highest version of a dependency encountered in the dependency graph is selected. Note that this differs from Maven's default behavior which is "nearest wins".

Results of the dependency resolution are written to the log with log level FINE.

  • Constructor Details

    • MvnRepoLookup

      public MvnRepoLookup()
      Initializes a new Maven repository lookup.
  • Method Details

    • addRepositories

      public MvnRepoLookup addRepositories(org.eclipse.aether.repository.RemoteRepository... repositories)
      Add repositories to be used for the lookup.
      Parameters:
      repositories - the repositories
      Returns:
      the mvn repo lookup
    • addRepository

      public MvnRepoLookup addRepository(String id, URI uri, MvnVersionType... supported)
      Add a repository that is to be used for the lookup.
      Parameters:
      id - the repository id
      uri - the repository uri
      supported - the supported version types
      Returns:
      the mvn repo lookup
    • bom

      public MvnRepoLookup bom(String... coordinates)
      Add a bill of materials. The coordinates are resolved as a dependency with scope import which is added to the dependencyManagement section when evaluating the effective model.
      Parameters:
      coordinates - the coordinates in the form groupId:artifactId:version
      Returns:
      the mvn repo lookup
    • resolve

      public MvnRepoLookup resolve(String... coordinates)
      Add artifacts, specified by their coordinates (groupId:artifactId:version) as resources.
      Parameters:
      coordinates - the coordinates in the form groupId:artifactId:version
      Returns:
      the mvn repo lookup
    • resolve

      public MvnRepoLookup resolve(Stream<? extends MvnRepoResource> resources)
      Add artifacts. The method handles MvnRepoBoms correctly.
      Parameters:
      resources - the resources
      Returns:
      the mvn repo lookup
    • probe

      public MvnRepoLookup probe()

      Failing to resolve the dependencies normally results in a BuildException, because the requested artifacts are assumed to be required for the build.

      By invoking this method the provider enters probe mode and returns an empty result stream instead of throwing an exception if the resolution fails.

      Returns:
      the mvn repo lookup
    • downloadSources

      public MvnRepoLookup downloadSources(boolean enable)
      Whether to also download the sources. Defaults to true.
      Parameters:
      enable - the enable
      Returns:
      the mvn repo lookup
    • downloadJavadoc

      public MvnRepoLookup downloadJavadoc(boolean enable)
      Whether to also download the javadoc. Defaults to true.
      Parameters:
      enable - the enable
      Returns:
      the mvn repo lookup
    • doProvide

      protected <T extends Resource> Collection<T> doProvide(ResourceRequest<T> request)
      Provide.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      request - the requested resources
      Returns:
      the stream