Let's say I have a project with 2 modules, and 3 pom.xml files (1 for Module A, 1 for Module B, 1 parent pom.xml)
I've added the following plugin that verifies the code coverage diff between my changeset and another branch, and fails if it's below a certain threshold https://github.com/SurpSG/diff-coverage-maven-plugin
If I make NO code changes:
mvn clean verify
-> success
mvn clean verify -T 1C -pl moduleA -am -U
-> success
mvn clean verify -T 1C -pl moduleA, moduleB -am -U
-> success
So as expected, my builds are passing because I made no code change.
Now if I make a code change to moduleA without proper unit test code coverage, here are the results.
mvn clean verify -T 1C -pl moduleA -am -U
-> fail for moduleB, skipping moduleA
mvn clean verify -T 1C -pl moduleB -am -U
-> success
mvn clean verify -T 1C -pl moduleA, moduleB -am -U
-> fail for moduleB, skipping moduleA
This last case is what is puzzling me, why would moduleB be failing? why is it not running for each module without side-effects?
The issue is that the failure message is really not helpful and pointing to the wrong service.
You are observing some weird behaviour because plugin's author didn't pay much attention to maven internals:
private val rootProjectDir: File
get() = reactorProjects[0].basedir
private fun collectExecFiles(): Set<File> {
return if (dataFileIncludes == null) {
setOf(dataFile)
} else {
FileUtils.getFiles(rootProjectDir, dataFileIncludes, dataFileExcludes).toSet()
}
}
Injecting reactorProjects
makes sense for @aggregator
mojos, because when we are dealing with multi-module project structures and have parent-child relations we need special handling of such cases (for example, there are two mojos in jacoco-maven-plugin
: report
and report-aggregate
). In your case plugin's author is trying to kill two rabbits with single shot, that in your particular case leads to the following:
when you run maven like -pl moduleA -am
then when maven executes verify phase of Module B
reactor projects are Module A, Module B
, plugin tries to pick up exec
files from Module A
directory and fails: Module A
depends on Module B
and there are no exec
files in Module A
directory.