首页 > 解决方案 > Maven 无法解析反应堆的依赖关系

问题描述

我在执行 `mvn clean package 时收到以下警告

07:02:39 [WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
07:02:39 [WARNING] o proj:fs-models:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] Try running the build up to the lifecycle phase "package"
07:02:39 [WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
07:02:39 [WARNING] o proj:fs-api:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] o proj:fs-models:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] Try running the build up to the lifecycle phase "package"
07:02:39 [WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
07:02:39 [WARNING] o proj:ep-api-models:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] o proj:pckg-models:jar:1.0.0-SNAPSHOT12345 (provided)
07:02:39 [WARNING] o proj:fs-api:jar:1.0.0-SNAPSHOT12345 (provided)
07:02:39 [WARNING] o proj:pckg-fs-models:jar:1.0.0-SNAPSHOT12345 (provided)
07:02:39 [WARNING] Try running the build up to the lifecycle phase "package"
07:02:39 [WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
07:02:39 [WARNING] o proj:models:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] o proj:ep-api-models:jar:1.0.0-SNAPSHOT12345 (compile)
07:02:39 [WARNING] Try running the build up to the lifecycle phase "package"

这些依赖项是反应器的一部分,但 maven 无法解决它。这可能是什么原因?

标签: mavenmaven-3

解决方案


问题是 maven 以某种方式尝试从远程存储库下载模块,但不应该这样做,因为它们尚未构建。就我而言,这是由调用聚合器目标的聚合器 Maven 插件引起的。这些聚合器目标需要有关项目依赖项的完整信息,因此 maven 会尝试下载它们。

我通过注释掉我项目中的所有聚合器插件并再次重建它来解决这个问题。如果 maven 不再下载它们,那么它们就是罪魁祸首。这些插件通常有他们的目标。例子:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>license-maven-plugin</artifactId>
    <inherited>false</inherited>
    <version>1.16</version>
    <executions>
        <execution>
            <id>default-cli</id>
            <goals>
                <goal>aggregate-add-third-party</goal>
            </goals>
        </execution>
    </executions>
</plugin>

注意aggregate-add-third-party-goal

相关文章:https ://blog.sonatype.com/2009/05/how-to-make-a-plugin-run-once-during-a-build/

一些插件就是我们所说的“聚合器”,这意味着它们实际上确实想要在执行之前获得有关完整多模块构建的所有信息。这些插件在项目树上运行时会导致 Maven 在调用插件的 execute() 方法之前解析所有子项。在这种模式下,插件只执行一次,但一次有效地在整个树上执行。(作为旁注,你永远不想在你的 pom 中绑定一个聚合器目标,因为这会导致插件运行一个 n!递归构建,因为生命周期会进入每个孩子并执行聚合器......这将导致 Maven解决所有孩子等)

确定导致插件后,您可以执行以下操作之一:

  1. 将它们移动到 Maven 配置文件上,以便它们仅在您使用配置文件时被激活
  2. 如果目标是报告,请将其移至 pom 上的报告部分(请参阅配置报告)。

推荐阅读