Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 2.9 KB

File metadata and controls

87 lines (64 loc) · 2.9 KB

Apache License, Version 2.0, January 2004 Github CI Maven Central

Enforcer Rules

Custom Maven Enforcer rules.

Rules

Usage

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>

banEmptyJavaFiles

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/>

requireDependencyManagement

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/>

Parameters

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.

Excluding dependencies

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>