[英]Maven multimodule project tries to download inner dependency from repository
I have a classical multimodule project with cross dependency我有一个具有交叉依赖性的经典多模块项目
parent pom:父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: mod2 pom:
<dependencies>
<dependency>
<groupId>grp</groupId>
<artifactId>mod1</artifactId>
</dependency>
...
It builds mvn clean install
fine, however when CI runs sonar using mvn sonar:sonar...
the maven tries to download mod1
snapshot dependency from repo, which supposed to be part of the same reactor.它可以很好地构建
mvn clean install
,但是当 CI 使用mvn sonar:sonar...
maven 尝试从 repo 下载mod1
快照依赖项,它应该是同一个反应堆的一部分。
Downloading from nexus: http://...mod1/1.0.0-SNAPSHOT/maven-metadata.xml
And it most cases it could not find the snapshot as it was not deployed yet, but it just keeps going.在大多数情况下,它找不到快照,因为它还没有部署,但它一直在继续。 However it slows down the build as I have several modules and each takes a while to make a roundtrip to repository.
但是,它会减慢构建速度,因为我有几个模块,每个模块都需要一段时间才能往返存储库。
Why?为什么?
The ${project.version}
is evaluating to a different value in mod2.pom (specifically, mod2's project version). ${project.version}
正在评估 mod2.pom 中的不同值(特别是 mod2 的项目版本)。 A better practice is to define a property in the properties section of the parent pom and reference that in the dependency management section.更好的做法是在父 pom 的属性部分中定义一个属性,并在依赖管理部分中引用它。
Please take a look at the Maven documentation here with the key explanation:请在此处查看 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.
I had a very similar problem: mvn install
was working fine, mvn sonar:sonar
wasn't.我有一个非常相似的问题:
mvn install
工作正常, mvn sonar:sonar
没有。
In my case, it was a test dependency:就我而言,这是一个测试依赖项:
<dependency>
<groupId>grp</groupId>
<artifactId>mod2</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
It was solved by adding test-compile
to the mvn
command:它是通过在
mvn
命令中添加test-compile
来解决的:
mvn test-compile sonar:sonar
I got the tip from this answer: https://stackoverflow.com/a/57226037/5269825我从这个答案中得到了提示: https://stackoverflow.com/a/57226037/5269825
I guess maven needs something (like compile
or compile-test
) to know that the dependency is another submodule.我猜 maven 需要一些东西(比如
compile
或compile-test
)才能知道依赖项是另一个子模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.