Class AbstractDependencyVersionsMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.basepom.mojo.dvc.AbstractDependencyVersionsMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, Context
Direct Known Subclasses:
DependencyVersionsCheckMojo, DependencyVersionsListMojo

public abstract class AbstractDependencyVersionsMojo extends org.apache.maven.plugin.AbstractMojo implements Context
Base code for all the mojos. Contains the dependency resolvers and the common options.
  • Field Details

    • LOG

      protected final PluginLog LOG
    • project

      @Parameter(defaultValue="${project}", readonly=true) public org.apache.maven.project.MavenProject project
    • mavenSession

      @Parameter(defaultValue="${session}", readonly=true) public org.apache.maven.execution.MavenSession mavenSession
    • reactorProjects

      @Parameter(defaultValue="${reactorProjects}", readonly=true, required=true) public List<org.apache.maven.project.MavenProject> reactorProjects
    • mavenProjectBuilder

      @Component public org.apache.maven.project.ProjectBuilder mavenProjectBuilder
    • projectDependenciesResolver

      @Component public org.apache.maven.project.ProjectDependenciesResolver projectDependenciesResolver
    • repositorySystem

      @Component public org.eclipse.aether.RepositorySystem repositorySystem
    • strategyProvider

      @Component public StrategyProvider strategyProvider
      The strategy provider. This can be requested by other pieces to add additional strategies.
    • exclusions

      @Parameter(alias="exceptions") public VersionCheckExcludes[] exclusions
      List of version checks that will be removed from the version check. This allows potential conflicts to be excluded.
       <exclusions>
         <exclusion>
           <dependency>...</dependency>
           <expected>...</expected>
           <resolved>...</resolved>
         </exclusion>
       </exclusions>
       

      Each element consists of a dependency pattern [groupId]:[artifactId] that supports wildcards and an expected version (which is the version is expected by the artifact) and a resolved version (the version that the dependency resolution has chosen).

    • skip

      @Parameter(defaultValue="false", property="dvc.skip") public boolean skip
      Skip the plugin execution.
    • includePomProjects

      @Parameter(defaultValue="false", property="dvc.include-pom-projects") public boolean includePomProjects
      Include POM projects when running on a multi-module project. Dependency resolution on a pom project almost never makes sense as it does not actually build any artifacts.
      Since:
      3.0.0
    • quiet

      @Parameter(defaultValue="false", property="dvc.quiet") public boolean quiet
      Silence all non-output and non-error messages.
      Since:
      3.0.0
    • scope

      @Parameter(defaultValue="test", property="scope") public String scope
      Dependency resolution scope. Defaults to test. Valid choices are compile+runtime, compile, test and runtime.
      Since:
      3.0.0
    • deepScan

      @Parameter(defaultValue="false", property="dvc.deep-scan") public boolean deepScan
      Use deep scan or regular scan. Deep scan looks at all dependencies in the dependency tree, while regular scan only looks one level deep into the direct dependencies.
      Since:
      3.0.0
    • directOnly

      @Parameter(defaultValue="false", property="dvc.direct-only") public boolean directOnly
      List only direct dependencies or all dependencies.
      Since:
      3.0.0
    • managedOnly

      @Parameter(defaultValue="false", property="dvc.managed-only") public boolean managedOnly
      List only managed dependencies or all dependencies.
      Since:
      3.0.0
    • fastResolution

      @Parameter(defaultValue="true", property="dvc.fast-resolution") public boolean fastResolution
      Run dependency resolution in parallel with multiple threads. Should only ever set to false if the plugin shows stability problems when resolving dependencies. Please file a bug in that case, too.
      Since:
      3.0.0
    • unresolvedSystemArtifactsFailBuild

      @Parameter(defaultValue="false", property="dvc.unresolved-system-artifacts-fail-build") protected boolean unresolvedSystemArtifactsFailBuild
      Fail the build if an artifact in system scope can not be resolved. Those are notoriously dependent on the local build environment and some outright fail (e.g. referencing the tools.jar, which no longer exists in a JDK8+ environment).
      Setting this flag to true will fail the build if any system scoped artifact can not be resolved. This is almost never desired, except when building a project with a direct system scoped dependency.
      Since:
      3.0.0
    • optionalDependenciesMustExist

      @Parameter(defaultValue="false", property="dvc.optional-dependencies-must-exist") protected boolean optionalDependenciesMustExist
      Require all optional dependencies to exist and fail the build if any optional dependency can not resolved. This is almost never needed and actually causes problems for some projects that use large public dependencies from central that in turn pull in non-public dependencies as optional.
      Since:
      3.2.0
    • resolvers

      @Parameter public ResolverDefinition[] resolvers
      List of resolvers to apply specific strategies to dependencies.
       <resolvers>
         <resolver>
           <strategy>...<strategy>
           <includes>
             <include>...<include>
           <includes>
         <resolver>
       <resolvers>
       
      A resolver maps a specific strategy to a list of includes. The include syntax is [group-id]:[artifact-id] where each pattern segment supports full and partial wildcards (*).
      The plugin includes some default strategies: apr, default, single-digit and two-digits-backward-compatible. Additional strategies can be defined and added to the plugin classpath.
    • defaultStrategy

      @Parameter(defaultValue="default", property="dvc.default-strategy") public String defaultStrategy
      Sets the default strategy to use to evaluate whether two dependency versions are compatible or not. The default resolution strategy matches the Maven dependency resolution itself; any two dependencies that maven considers compatible will be accepted.
      Since:
      3.0.0
    • strategyCache

      protected StrategyCache strategyCache
  • Constructor Details

    • AbstractDependencyVersionsMojo

      public AbstractDependencyVersionsMojo()
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • doExecute

      protected abstract void doExecute(com.google.common.collect.ImmutableSetMultimap<QualifiedName,VersionResolutionCollection> resolutionMap, DependencyMap rootDependencyMap) throws Exception
      Subclasses need to implement this method.
      Parameters:
      resolutionMap - The prebuilt resolution map from qualified names to version resolution collections.
      rootDependencyMap - The prebuilt dependency map for all the root dependencies.
      Throws:
      Exception - When an execution error occurs.
    • createScopeFilter

      protected ScopeLimitingFilter createScopeFilter()
      Defines the scope used to resolve the project dependencies. The project dependencies will be limited to the dependencies that match this filter. The list mojo overrides this to limit the scope in which dependencies are listed. By default, include everything.
      Returns:
      The ScopeLimitingFilter instance for the project dependencies.
    • useFastResolution

      public boolean useFastResolution()
      Specified by:
      useFastResolution in interface Context
      Returns:
      True if the resolver should use multiple threads.
    • useDeepScan

      public boolean useDeepScan()
      Specified by:
      useDeepScan in interface Context
      Returns:
      True if a deep scan should be performed instead of regular scan.
    • isOptionalDependenciesMustExist

      public boolean isOptionalDependenciesMustExist()
      Specified by:
      isOptionalDependenciesMustExist in interface Context
      Returns:
      True if all optional dependencies must exist.
    • getStrategyCache

      public StrategyCache getStrategyCache()
      Specified by:
      getStrategyCache in interface Context
      Returns:
      The lookup cache for the Strategy resolution
    • getProjectBuilder

      public org.apache.maven.project.ProjectBuilder getProjectBuilder()
      Specified by:
      getProjectBuilder in interface Context
      Returns:
      The Maven project builder.
    • getProjectDependenciesResolver

      public org.apache.maven.project.ProjectDependenciesResolver getProjectDependenciesResolver()
      Specified by:
      getProjectDependenciesResolver in interface Context
      Returns:
      The Maven project dependency resolver.
    • getRootProject

      public org.apache.maven.project.MavenProject getRootProject()
      Specified by:
      getRootProject in interface Context
      Returns:
      The root project.
    • getReactorProjects

      public List<org.apache.maven.project.MavenProject> getReactorProjects()
      Specified by:
      getReactorProjects in interface Context
      Returns:
      All projects that are in the current reactor.
    • getRepositorySystemSession

      public org.eclipse.aether.RepositorySystemSession getRepositorySystemSession()
      Specified by:
      getRepositorySystemSession in interface Context
      Returns:
      The repository session
    • getRepositorySystem

      public org.eclipse.aether.RepositorySystem getRepositorySystem()
      Specified by:
      getRepositorySystem in interface Context
      Returns:
      The repository system for dependency resolution.
    • createProjectBuildingRequest

      public org.apache.maven.project.ProjectBuildingRequest createProjectBuildingRequest()
      Specified by:
      createProjectBuildingRequest in interface Context
      Returns:
      A new project building request.
    • createVersionRangeRequest

      public org.eclipse.aether.resolution.VersionRangeRequest createVersionRangeRequest(org.eclipse.aether.artifact.Artifact artifact)
      Specified by:
      createVersionRangeRequest in interface Context
      Parameters:
      artifact - The artifact to define the version range resolution request.
      Returns:
      A version range resolution request.
    • getExclusions

      public List<VersionCheckExcludes> getExclusions()
      Specified by:
      getExclusions in interface Context
      Returns:
      All configured exclusions.
    • isUnresolvedSystemArtifactsFailBuild

      public boolean isUnresolvedSystemArtifactsFailBuild()
      Specified by:
      isUnresolvedSystemArtifactsFailBuild in interface Context
      Returns:
      True if any unresolved system artifacts should fail the build.