繁体   English   中英

Maven 多模块项目尝试从存储库下载内部依赖项

[英]Maven multimodule project tries to download inner dependency from repository

我有一个具有交叉依赖性的经典多模块项目

父POM:

<modules>
    <module>mod1</module>
    <module>mod2</module>
</modules>
...
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>grp</groupId>
            <artifactId>mod1</artifactId>
            <version>${project.version}</version>
        </dependency>
...

mod2 pom:

<dependencies>
    <dependency>
      <groupId>grp</groupId>
      <artifactId>mod1</artifactId>
    </dependency>
 ...

它可以很好地构建mvn clean install ,但是当 CI 使用mvn sonar:sonar... maven 尝试从 repo 下载mod1快照依赖项,它应该是同一个反应堆的一部分。

Downloading from nexus: http://...mod1/1.0.0-SNAPSHOT/maven-metadata.xml

在大多数情况下,它找不到快照,因为它还没有部署,但它一直在继续。 但是,它会减慢构建速度,因为我有几个模块,每个模块都需要一段时间才能往返存储库。

为什么?

${project.version}正在评估 mod2.pom 中的不同值(特别是 mod2 的项目版本)。 更好的做法是在父 pom 的属性部分中定义一个属性,并在依赖管理部分中引用它。

请在此处查看 Maven 文档及其关键说明:

One factor to note is that these variables are processed after inheritance as outlined above. This means that if a parent project uses a variable, then its definition in the child, not the parent, will be the one eventually used.

我有一个非常相似的问题: mvn install工作正常, mvn sonar:sonar没有。

就我而言,这是一个测试依赖项:

<dependency>
  <groupId>grp</groupId>
  <artifactId>mod2</artifactId>
  <version>${project.version}</version>
  <type>test-jar</type>
  <scope>test</scope>
</dependency>

它是通过在mvn命令中添加test-compile来解决的:

mvn test-compile sonar:sonar

我从这个答案中得到了提示: https://stackoverflow.com/a/57226037/5269825

我猜 maven 需要一些东西(比如compilecompile-test )才能知道依赖项是另一个子模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM