Jenkins fails to build multi-module Maven project

不羁的心 提交于 2020-05-29 05:39:32

问题


I have a multi-module Maven project where I have multiple micro services as modules so I have modules listed in my parent pom.xml like below:

<modules>
    <module>core</module>
    <module>model-base</module>
    <module>module1</module>
    <module>module2</module>
    ...
    <module>module5</module>
    <module>module7</module>
    <module>module6</module>
</modules>

Here the module7 is dependent on module5, 6 so I have dependencies listed like below in my module7 pom.xml:

<parent>
    <artifactId>pojectA</artifactId>
    <groupId>com.domain</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module7</artifactId>
<dependencies>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>module5</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.domain</groupId>
        <artifactId>module6</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies> 

When I run mvn clean package in my local the module5, 6 called before the module7 as expected but in Jenkins it is trying to build module 5 then module7 making build fail saying:

[ERROR] Failed to execute goal on project module7: Could not resolve dependencies for project module7:jar:1.0-SNAPSHOT: Could not find artifact module6:jar:1.0-SNAPSHOT -> [Help 1]

Do I need to run any other jobs or re-order the modules in my pom.xml, how is it differ from local to Jenkins? Appreciate any help on this.


回答1:


As is probably quite well understood, the issue is that the dependencies between the child modules fail because they aren't installed in the local repository yet (because they are yet to be built). The goal that causes this (for me anyway) is mvn test, which is invoked by mvn package. Your local build probably works because at some point you've done a mvn install and this has bootstrapped your system.

In Jenkins the only way I've found to make these builds work is to use the Pre-build step invoking a Maven target of install, and then build the main step as usual.




回答2:


The order of modules is not relevant. Maven recognizes which project depends on which other project(s) and sets the build order in the reactor accordingly. See POM Reference, Aggregation (or Multi-Module):

You do not need to consider the inter-module dependencies yourself when listing the modules, i.e. the ordering of the modules given by the POM is not important. Maven will topologically sort the modules such that dependencies are always build before dependent modules.



来源:https://stackoverflow.com/questions/38064925/jenkins-fails-to-build-multi-module-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!