Custom Maven Enforcer rules.
Add enforcer-rules as a dependency of the maven-enforcer-plugin and configure the desired rules inside an enforce execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<dependencies>
<dependency>
<groupId>io.github.shitikanth</groupId>
<artifactId>enforcer-rules</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banEmptyJavaFiles/>
<requireDependencyManagement/>
</rules>
</configuration>
</execution>
</executions>
</plugin>Empty Java source files — or files that contain no top-level type declaration whose name matches the file name — are detected as stale by the Maven Compiler Plugin, causing unnecessary recompilation on every build.
This rule fails the build if any such file is found.
<banEmptyJavaFiles/>Fails the build if any project dependency declares its version inline rather than inheriting it from <dependencyManagement>. This encourages centralised version management and prevents version drift across modules.
<requireDependencyManagement/>| Parameter | Type | Default | Description |
|---|---|---|---|
excludes |
List<String> |
(empty) | Dependency coordinates to exempt from the check, in groupId:artifactId format. * is a glob wildcard and may appear anywhere within either segment. |
Use <excludes> to exempt specific dependencies. The most common use case is a multi-module project where modules depend on each other with <version>${project.version}</version> — these do not need a <dependencyManagement> entry.
<requireDependencyManagement>
<excludes>
<!-- exempt all sibling modules in this reactor -->
<exclude>${project.groupId}:*</exclude>
</excludes>
</requireDependencyManagement>