Maven enforcer issue when running from reactor level
Asked Answered
D

2

6

Maven version used: 3.5.2, 3.5.3

mvn clean package -pl <root-artifact-id>:<module-name>

is failing saying

    [WARNING] Rule 3: org.apache.maven.plugins.enforcer.ReactorModuleConvergence failed with message:
Module parents have been found which could not be found in the reactor.
 module: <artifact:id>:<module-name>:war:1.0-SNAPSHOT

But working fine when running the mvn clean package from the module level though. Thats the only warning message in the trace causing the enforcer to fail the package build.

Drama answered 1/6, 2018 at 15:58 Comment(2)
could you please provide the enforcer configuration xml and which pom.xml you have defined that?Footwork
gist.github.com/achittin/9018c7d99fe9203e07f35c1ada97bbf1Drama
W
8

It's a very old reported bug but nobody seems to do anything about it: https://issues.apache.org/jira/browse/MENFORCER-189

Root cause would be that it compares the artifactid (module-name) of the project passed in the -pl paramater with the artifactid (reactor) of its parent. Which would never be the same and thus will always give this error.

For us the fix was to disable the enforcer plugin when using this execution (other executions without the -pl like 'clean install' are fine)

mvn clean install
mvn package -pl module-name -Denforcer.skip=true

Edit:
Another option is to specify the reactor project in the build using '.' (note: this will also package the reactor)

mnv clean package -pl .,module-name
Withindoors answered 22/10, 2019 at 9:21 Comment(0)
A
2

Try including --also-make or -am, for example:

mvn -am -pl <root-artifact-id>:<module-name> clean package

Even if the module you're building doesn't have a dependency on another module within the build, this triggers a Reactor build that includes the given module and the parent POM together, and their relationship is then able to be verified by Enforcer without skipping. (Works with Maven 3.6.2 in my case).

Apothecium answered 28/10, 2019 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.