Maven enforcer issue when running from reactor level

3.1k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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
0
On

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).