在Maven中跟踪托管依赖项版本

Sti*_*ael 8 dependencies pom.xml maven

假设我有一个包含大量依赖项的复杂项目.依赖项的版本由许多导入范围poms管理.我的项目依赖于工件group:artifact,它依赖于工件group:transitive-dependency.当我跑步时,dependency:tree我看到这样的事情:

+- group:artifact:jar:1.3
   +- group:transitive-dependency:jar:1.1 (version managed from 1.3)
Run Code Online (Sandbox Code Playgroud)

问题是group:artifact:1.3需要group:transitive-dependency1.3或更高版本.当然其中一个导入poms正在强制使用错误的版本.但除了搜索所有这些之外,还有什么方法可以知道哪一个是什么?

小智 5

您应该尝试使用maven-enforcer-plugin并将其配置为执行DependencyConvergence,例如

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.2</version>
    <executions>
      <execution>
        <id>enforce</id>
        <configuration>
          <rules>
            <DependencyConvergence/>
          </rules>
        </configuration>
        <goals>
          <goal>enforce</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

这将显示哪些顶级依赖项在其依赖关系树中具有不同版本的其他依赖项.然后,使用排除项抑制不需要的依赖项变体.