4

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
user1653027
  • 789
  • 1
  • 16
  • 38
  • Are you sure that Jenkins really builds the same as you build locally? Is this the only error in the build's Console Output? Can you supply the _Reactor Build Order_ and _Reactor Summary_ parts from the Console Output? – Gerold Broser Jun 28 '16 at 00:40
  • Have you seen the reactor is according to your dependencies? Cause module5, module6 must be built before module7 ? – khmarbaise Jun 28 '16 at 06:43

3 Answers3

1

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.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • thanks for the reply ... i understood that ordering modules in pom doesn't matter for maven multimodule . So when we run `mvn clean package` in Jenkins or local the order should be same as my local build. But why my local build gets success and jenkins fails? any idea? – user1653027 Jun 28 '16 at 05:27
0

Add Pre-Step as per below attached screenshot. This will compile all your top modules. Then we can execute which ever module we want.

ScreenShotLink

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
-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.

Jenkins config

Nigel
  • 1,203
  • 2
  • 11
  • 20