Maven Reactor builds so it doesn't satisfy all dependencies

I am having trouble ordering an order in a SNAPSHOT build using Maven. The reactor builds all cans out of order.

Below is an example of a structure to recreate the problem (the project I'm having problems with is much larger> 100 jars):

pom.xml        [reactor]
parent/pom.xml [parent]
jar1/pom.xml
jar2/pom.xml
jar3/pom.xml

      

pom.xml [reactor]

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <packaging>pom</packaging>
  <groupId>com.test.buildorder</groupId>
  <artifactId>reactor</artifactId>
  <version>1.0</version>
  <modules>
    <module>jar3</module>
    <module>jar2</module>
    <module>jar1</module>
  </modules>
</project>

      

parent / pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.buildorder</groupId>
  <artifactId>parent</artifactId>
  <version>1.1</version>
  <packaging>pom</packaging>

  <dependencyManagement>
  <dependencies>
      <dependency>
        <groupId>com.test.buildorder</groupId>
        <artifactId>jar1</artifactId>
        <version>1.1</version>
      </dependency>
      <dependency>
        <groupId>com.test.buildorder</groupId>
        <artifactId>jar2</artifactId>
        <version>1.0</version>
      </dependency>
      <dependency>
        <groupId>com.test.buildorder</groupId>
        <artifactId>jar3</artifactId>
        <version>1.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

      

jar1 / pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.buildorder</groupId>
  <artifactId>jar1</artifactId>
  <version>1.1</version>
  <parent>
    <groupId>com.test.buildorder</groupId>
    <artifactId>parent</artifactId>
    <version>1.1</version>
  </parent>
</project>

      

jar2 / pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.buildorder</groupId>
  <artifactId>jar2</artifactId>
  <version>1.1</version>
  <parent>
    <groupId>com.test.buildorder</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>com.test.buildorder</groupId>
      <artifactId>jar1</artifactId>
    </dependency>
  </dependencies>
</project>

      

jar3 / pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.buildorder</groupId>
  <artifactId>jar3</artifactId>
  <version>1.1</version>
  <parent>
    <groupId>com.test.buildorder</groupId>
    <artifactId>parent</artifactId>
    <version>1.1</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>com.test.buildorder</groupId>
      <artifactId>jar2</artifactId>
    </dependency>
  </dependencies>
</project>

      

My repository (local in this case) only has 1.0 released versions of each jar and jar3-1.0 depended on jar2-1.0 and jar2-1.0 depended on jar1-1.0 and each had a parent-1.0 (I can post this code if necessary, but my question is already very long, so I'll postpone if I don't ask).

Now I install the parent pom 1.1 and then I try to run the install in reactor and get the following result.

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.test.buildorder:jar3:jar:1.1
[WARNING] 'parent.relativePath' points at com.test.buildorder:reactor instead of com.test.buildorder:parent, please verify your project structure @ line 6, column 11
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.test.buildorder:jar2:jar:1.1
[WARNING] 'parent.relativePath' points at com.test.buildorder:reactor instead of com.test.buildorder:parent, please verify your project structure @ line 6, column 11
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.test.buildorder:jar1:jar:1.1
[WARNING] 'parent.relativePath' points at com.test.buildorder:reactor instead of com.test.buildorder:parent, please verify your project structure @ line 6, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] jar3
[INFO] jar2
[INFO] jar1
[INFO] reactor
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jar3 1.1
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/com/test/buildorder/jar1/1.1/jar1-1.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] jar3 ............................................... FAILURE [  0.645 s]
[INFO] jar2 ............................................... SKIPPED
[INFO] jar1 ............................................... SKIPPED
[INFO] reactor ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.775 s
[INFO] Finished at: 2015-06-03T16:56:04-05:00
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jar3: Could not resolve dependencies for project com.test.buildorder:jar3:jar:1.1: Could not find artifact com.test.buildorder:jar1:jar:1.1 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

      

When I built version 1.0, Reactor was smart enough to implement a dependency tree jar3-1.0 -> jar2-1.0 -> jar1-1.0 and build in jar1, jar2, jar3 order to satisfy dependencies.

Now, although jar3-1.1 depends on jar2-1.0 (which is in the repo), the reactor doesn't assume jar1 needs to be built first, but debugging (using the -X argument) shows the dependency tree:

[DEBUG] com.test.buildorder:jar3:jar:1.1
[DEBUG]    com.test.buildorder:jar2:jar:1.0:compile
[DEBUG]       com.test.buildorder:jar1:jar:1.1:compile (version managed from 1.0 by com.test.buildorder:parent:1.1)

      

So, I have a few questions about this scenario:
1. Why does maven think jar3-1.1 has a transitive dependency on jar1-1.1?
2. Why doesn't the reactor understand this transitive dependence and builds it in the required order to satisfy it?
3. What can I do to prevent this problem from occurring? (Preferably, without rewriting more than 100 rm.)

Edit: Found an answer to question one, and one solution to question three. But I would still like to hear about the second question.

1. Since I have never defined the scope for dependencies, maven determines the default scope compile

. Because of this, the dependency from jar2 to jar1 will show up as a transitive dependency for jars that depend on jar2 (like jar3). (version managed from 1.0 by com.test.buildorder:parent:1.1)

tells me that the dependency is from jar2-1.0 to jar1-1.0, but since the parent specifies a different version for jar 1 (1.1), it accepts that.

3. If I change the scope of the dependency from jar2 to jar1 to provided

, the dependency is no longer transitive. This assumes that all the required banks will be present at runtime, so this may not be a solution for everyone who faces this problem. Below is a guide to the scopes available in Maven .

+6


source to share


3 answers


I have installed all your projects with all versions set to 1.0

here. Then I changed the versions as you stated and got the same error.

After changing the POM reactor

to:

 <modules>
    <module>jar1</module>
    <module>jar2</module>
    <module>jar3</module>
</modules>

      

... the build was successful.

I went through the Guide to Working with Multiple Modules, Reactor Sorting and the last option:

  • the order declared in the element <modules>

    (unless another rule applies)


After reading the following sentence:

Please note that only "instances" of the link are used dependencyManagement

and pluginManagement

will not change the sort order of the reactor

  • I rebuilt the reactor

    POM
  • I commented out the section <dependencyManagement>

    in the POM parent

    and added <version>

    to the POM jar2

    and jar3

    explicitly

and the build finished with:

[INFO] Reactor Build Order
[INFO]
[INFO] jar3
[INFO] jar1
[INFO] jar2
[INFO] reactor

      

+6


source


[WARNING] Some problems came up when creating an efficient model for com.test.buildorder: jar3: jar: 1.1 [WARNING] "parent.relativePath" points to com.test.buildorder: reactor instead of com.test.buildorder: parent.

Since your reactor is not a parent, I assume you need to explicitly specify the relative path



<parent>
    <groupId>com.test.buildorder</groupId>
    <artifactId>parent</artifactId>
    <version>1.1</version>
    <relativePath>../parent</relativePath>
  </parent>

      

Also, you have different versions of jar2

1.0

and 1.1

. align them

0


source


to question 2: Maven reactor ordering does not work with transitive dependencies, it only calculates direct dependencies:

  • jar3-1.1 depends on jar2-1.0 (which is not in the reactor)

  • jar2-1.1 depends on jar1-1.1

  • jar1-1.1

in such a situation there is no link from jar3-1.1 to jar1-1.1

you are not expected to mix jar2-1.1 in reactor with jar2-1.0 in your dependency management

0


source







All Articles