【问题标题】:Why is maven enforcer plugin failing with maven version 3.6.1 but passing with 3.6.2?为什么 maven 强制插件插件在 maven 版本 3.6.1 中失败但在 3.6.2 中通过?
【发布时间】:2020-08-29 06:42:53
【问题描述】:

在我的一个项目中,我正在尝试将 DependencyConvergence 规则与 maven enforcer 插件一起使用。我观察到,如果我使用 Maven 3.6.1,那么执行器会因以下错误而失败,但同样适用于 maven 3.6.2。

有人可以告诉我 Maven 3.6.2 中的哪些更改导致 DependencyConvergence 传入 3.6.2 但在低于 3.6.2 的其他 maven 版本中失败?

我在GitHub 上放置了一个示例项目,可以在其中重现此问题。

Debrajs-MacBook-Air:es-plugins debrajmanna$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

maven-enforcer-plugin - 3.0.0-M2

Debrajs-MacBook-Air:es-plugins debrajmanna$ ~/Downloads/apache-maven-3.6.1/bin/mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] es-plugins                                                         [pom]
[INFO] dedup                                                              [jar]
[INFO]
[INFO] -----------------------< org.example:es-plugins >-----------------------
[INFO] Building es-plugins 1.0-SNAPSHOT                                   [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (javaversion-dependencyconvergence) @ es-plugins ---
[INFO]
[INFO] -------------------------< org.example:dedup >--------------------------
[INFO] Building dedup 1.0-SNAPSHOT                                        [2/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (javaversion-dependencyconvergence) @ dedup ---
[WARNING]
Dependency convergence error for com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.1 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.1
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.apache.lucene:lucene-test-framework:8.5.1
      +-com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.2

[WARNING]
Dependency convergence error for commons-logging:commons-logging:1.2 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpclient:4.5.10
        +-commons-logging:commons-logging:1.2
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpasyncclient:4.1.4
        +-commons-logging:commons-logging:1.2
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-commons-logging:commons-logging:1.1.3
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client-sniffer:7.7.1
      +-commons-logging:commons-logging:1.1.3
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-commons-logging:commons-logging:1.1.3

[WARNING]
Dependency convergence error for org.apache.httpcomponents:httpcore:4.4.12 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpclient:4.5.10
        +-org.apache.httpcomponents:httpcore:4.4.12
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpcore:4.4.12
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpasyncclient:4.1.4
        +-org.apache.httpcomponents:httpcore:4.4.10
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client-sniffer:7.7.1
      +-org.apache.httpcomponents:httpcore:4.4.12

[WARNING]
Dependency convergence error for org.apache.httpcomponents:httpclient:4.5.10 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpclient:4.5.10
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpasyncclient:4.1.4
        +-org.apache.httpcomponents:httpclient:4.5.6
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client-sniffer:7.7.1
      +-org.apache.httpcomponents:httpclient:4.5.10

[WARNING]
Dependency convergence error for org.apache.httpcomponents:httpcore-nio:4.4.10 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpasyncclient:4.1.4
        +-org.apache.httpcomponents:httpcore-nio:4.4.10
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.elasticsearch.client:elasticsearch-rest-client:7.7.1
      +-org.apache.httpcomponents:httpcore-nio:4.4.12

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability. See above detailed error message.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for es-plugins 1.0-SNAPSHOT:
[INFO]
[INFO] es-plugins ......................................... SUCCESS [  3.047 s]
[INFO] dedup .............................................. FAILURE [  0.856 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.131 s
[INFO] Finished at: 2020-08-29T11:41:55+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce (javaversion-dependencyconvergence) on project dedup: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :dedup

同样适用于 Maven 3.6.2。

Debrajs-MacBook-Air:es-plugins debrajmanna$ ~/Downloads/apache-maven-3.6.2/bin/mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] es-plugins                                                         [pom]
[INFO] dedup                                                              [jar]
[INFO]
[INFO] -----------------------< org.example:es-plugins >-----------------------
[INFO] Building es-plugins 1.0-SNAPSHOT                                   [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (javaversion-dependencyconvergence) @ es-plugins ---
[INFO]
[INFO] -------------------------< org.example:dedup >--------------------------
[INFO] Building dedup 1.0-SNAPSHOT                                        [2/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (javaversion-dependencyconvergence) @ dedup ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for es-plugins 1.0-SNAPSHOT:
[INFO]
[INFO] es-plugins ......................................... SUCCESS [  1.743 s]
[INFO] dedup .............................................. SUCCESS [  0.510 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.462 s
[INFO] Finished at: 2020-08-29T11:42:06+05:30
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 不幸的是,我无法重现此问题。此外,如果我跳过执行者,整个项目将无法构建......
  • 你试过哪个 maven 版本?我尝试使用 maven 3.6.1、3.5.3 和 3.6.3。它仅适用于 3.6.3。
  • 这是更大项目的一部分,我试图简化事情并错过了删除装配部分,因为我们只对validate 阶段感兴趣。无论如何,我已经更新了项目代码。如果你现在只注释掉 es-plugins 中的 maven-enforcer-plugin 部分,它会构建得很好。
  • 您是否设置了一些环境变量,例如M2_HOME 或类似的东西?
  • 下次请尝试所有次要版本,直到确定错误的确切位置,因为事实证明 3.6.2 也可以。我编辑了你的问题以反映这一点。本来可以节省我几分钟的时间。 :) 无论如何,没什么大不了的。

标签: java maven java-8 maven-3


【解决方案1】:

它与MENFORCER-195MNG-6713 有关,它们是Maven 3.6.2 中修复的错误。

如果您使用的是 3.6.2,请小心,因为该区域中有 a further regression,直到 3.6.3 才修复(不影响您的示例)。


我是如何找到这些票的:

让我们分别看一下每个故障。从第一个开始是有意义的:

Dependency convergence error for com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.1 paths to dependency are:
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.1
and
+-org.example:dedup:1.0-SNAPSHOT
  +-org.elasticsearch.test:framework:7.7.1
    +-org.apache.lucene:lucene-test-framework:8.5.1
      +-com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.2

我们来看看org.elasticsearch.test:framework's POM的相关部分:

<dependency>
    <groupId>com.carrotsearch.randomizedtesting</groupId>
    <artifactId>randomizedtesting-runner</artifactId>
    <version>2.7.1</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <artifactId>*</artifactId>
            <groupId>*</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-test-framework</artifactId>
    <version>8.5.1</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
          <artifactId>*</artifactId>
          <groupId>*</groupId>
      </exclusion>
    </exclusions>
</dependency>

很明显,我们可以看到 Lucene 的所有传递依赖项都应该被排除。但是,如果我们回到这部分错误,Enforcer 插件所抱怨的 2.7.2 版本甚至不应该在依赖关系树中!

...
   +-org.apache.lucene:lucene-test-framework:8.5.1
        +-com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.7.2

当我为两个版本的 Maven(3.6.1 和 3.6.2)打印 Maven 依赖树时,我看到的唯一 randomizedtesting-runner 实例是 2.7.1 版本,所以这里发生了一些可疑的事情。

我的直觉告诉我,通配符排除可能是罪魁祸首,所以从那里只需搜索the release notes 以查找“排除”或“通配符”之类的内容。事实证明我是对的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 2011-08-27
    • 2021-10-02
    • 1970-01-01
    相关资源
    最近更新 更多