Maven Enforcer Rule dependOnAllProjects, com.github.mikkoi:maven-enforcer-rule-depend-on-all-projects is a user-created custom rule to force any Maven project in a multi module build to have a dependency on all other projects in the same build.
The rule ensures that when a multi module Maven project is reconfigured by adding or removing subprojects, all projects are listed as dependencies for that subproject in which maven-enforcer-plugin is executed. If used in a CI pipeline or in any similar manner, this Maven Enforcer rule will keep the subproject up to date.
If there is something that needs to be done after everything else in the build is completed, it can be placed into its own subproject with maven-enforcer-plugin configured with this rule.
Use Case: JaCoCo
JaCoCo is a free Java code coverage library. When used in a multi module project, after building and running tests for all subprojects that contain source code, the build must execute jacoco:report-aggregate.
The aggregated report is generated from all subprojects that the project depends on, and optionally from the subproject itself. The class and source files, as well as JaCoCo execution data files, will be collected from those projects.
With Maven Enforcer Rule dependOnAllProjects, the subproject can ensure that all other subprojects are indeed listed as its dependencies, or that exceptions are configured properly.
In big projects, where developers are adding and removing subprojects all the time, it is easy to forget to update the "report-aggregate" subproject. With Enforcer Rule dependOnAllProjects this won't be an issue any more.
There are also parameters includes and excludes to limit which projects are required. Both parameters support wildcards. If a project is excluded by precise name, and Maven Enforcer notices that there is no such project in the build, the build will fail with an error to prevent configuration from becoming obsolete.
Example Configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.github.mikkoi</groupId>
<artifactId>maven-enforcer-rule-depend-on-all-projects</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>depend-on-all-projects</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<dependOnAllProjects>
<excludes>
<exclude>com.example:shared-proj</exclude>
</excludes>
</dependOnAllProjects>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Top comments (0)