Fork me on GitHub

Quickstart

This quickstart shows how to configure the Maven Enforcer Plugin to use the maven-enforcer-rule-depend-on-all-projects rule in a multimodule build.

Prerequisites

  1. Maven 3.x or later.
  2. The rule artifact installed in your local repository or available from a remote repository.

Usage

  1. Add the Maven Enforcer Plugin to the project where you want to enforce the rule.
  2. Configure the rule inside the plugin configuration.
  3. Run the Enforcer Plugin during your build or call it manually.

Example configuration

Add the following snippet to the build section of the POM where you want the rule to run:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <id>enforce-dependencies</id>
                <goals>
                    <goal>enforce</goal>
                </goals>
                <configuration>
                    <rules>
                        <dependOnAllProjects implementation="com.github.mikkoi:maven-enforcer-rule-depend-on-all-projects:0.1.1">
                            <includeRootProject>false</includeRootProject>
                            <errorIfUnknownProject>false</errorIfUnknownProject>
                        </dependOnAllProjects>
                    </rules>
                    <fail>true</fail>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

Run the rule

Execute the rule with:

mvn enforcer:enforce

Or run the full build to execute the plugin as part of the lifecycle:

mvn verify

Notes

  1. By default, all reactor projects are considered unless includes or excludes are specified.
  2. Use the includes and excludes configuration parameters to control which projects are required as dependencies.
  3. Set includeRootProject to true to include the root project in the dependency list.
  4. Enable errorIfUnknownProject to fail the build when an include or exclude references a project not present in the current reactor.