com.github.ferstl:pedantic-pom-enforcers

The Pedantic POM Enforcers consist of several Maven enforcer rules that help you keep your project setup consistent and organized.


License
Apache-2.0

Documentation

Pedantic POM Enforcers

- One does not simply write a POM file

Build Status Maven Central Coverage Status license

Have you ever experienced symptoms like headaches, unfocused anger or a feeling of total resignation when looking at a Maven project where everybody adds and changes stuff just as they need? Do people call you a "POM-Nazi" if you show them how to setup proper and well organized projects?

If so, the Pedantic POM Enforcers are absolutely the thing you need!

What are the Pedantic POM Enforcers?

The Pedantic POM Enforcers consist of several Maven enforcer rules that help you keep your project setup consistent and organized. For example, the enforcer rules ensure that your POM files are organized in a well-defined manner, that your <modules>/<dependencyManagement>/<dependencies>/<pluginManagement> sections are sorted in a reasonable way and that version numbers, plugin configurations, etc. are defined only in places where it makes sense.

Release Notes / Solved Issues

How to use the Pedantic POM Enforcers

The Pedantic POM Enforcers are available on Maven Central. So no further repository configuration is required.

To activate the enforcer rules, just declare them in the configuration of the maven-enforcer-plugin. The simplest way of doing this is using the CompoundPedanticEnforcer, which is able to aggregate all chosen enforcer rules. The compound enforcer is also more efficient than using the single enforcer rules separately.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>3.3.0</version>
      <!-- Add the pedantic-pom-enforcers as dependency -->
      <dependencies>
        <dependency>
          <groupId>com.github.ferstl</groupId>
          <artifactId>pedantic-pom-enforcers</artifactId>
          <version>2.2.0</version>
        </dependency>
      </dependencies>
      <!-- Configure the enforcer rules -->
      <executions>
        <execution>
          <id>pedantic-pom-enforcers</id>
          <phase>validate</phase>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <compound implementation="com.github.ferstl.maven.pomenforcers.CompoundPedanticEnforcer">
                <!-- Enforcers -->
                <enforcers>POM_SECTION_ORDER,MODULE_ORDER,DEPENDENCY_MANAGEMENT_ORDER,DEPENDENCY_ORDER,PLUGIN_MANAGEMENT_ORDER</enforcers>
              
                <!-- Further configuration of the declared enforcer rules -->
                ...
              </compound>
            </rules>
            <fail>true</fail>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
</build>

Why comma-separated Strings?

You may wonder why comma-separated strings are used to configure the enforcer rules although the maven-enforcer-plugin supports structured configurations like

<!-- Note: This configuration is not valid for the Pedantic POM Enforcers! -->
<enforcers>
  <enforcer>POM_SECTION_ORDER</enforcer>
  <enforcer>MODULE_ORDER</enforcer>
  ...
</enforcers>

The reason is simple: The comma-separated strings can be defined as <properties> in a POM file. In case a submodule requires a different configuration, the properties can easily be overwritten in the submodule's POM. This allows to add or remove specific enforcer rules or to alter configuration values without redefining the whole plugin configuration.

Available Enforcer Rules

These are the currently available Pedantic POM Enforcers. The ID in parentheses is required by the CompoundPedanticEnforcer's configuration. For further details take a look at the Wiki.

Enforcer ID Description
CompoundPedanticEnforcer n/a Used to aggregate several pedantic enforcer rules.
PedanticPomSectionOrderEnforcer POM_SECTION_ORDER This enforcer makes sure that the sections in your POM files are in a defined order.
PedanticModuleOrderEnforcer MODULE_ORDER This enforcer makes sure that your modules section is sorted alphabetically.
PedanticDependencyManagementOrderEnforcer DEPENDENCY_MANAGEMENT_ORDER This enforcer makes sure that all artifacts in your dependency management are ordered.
PedanticDependencyManagementLocationEnforcer DEPENDENCY_MANAGEMENT_LOCATION Enforces that only a well-defined set of POMs may declare dependency management.
PedanticDependencyOrderEnforcer DEPENDENCY_ORDER This enforcer makes sure that all artifacts in your dependencies section are ordered.
PedanticDependencyConfigurationEnforcer DEPENDENCY_CONFIGURATION This enforcer makes sure that dependency versions and exclusions are declared in the <dependencyManagement> section.
PedanticDependencyElementEnforcer DEPENDENCY_ELEMENT This enforcer makes sure that elements in the and sections are ordered.
PedanticDependencyScopeEnforcer DEPENDENCY_SCOPE Enforces that the configured dependencies have to be defined within a specific scope.
PedanticPluginManagementOrderEnforcer PLUGIN_MANAGEMENT_ORDER This enforcer makes sure that all plugins in your plugin management section are ordered.
PedanticPluginConfigurationEnforcer PLUGIN_CONFIGURATION Enforces that plugin versions, configurations and dependencies are defined in the <pluginManagement> section.
PedanticPluginElementEnforcer PLUGIN_ELEMENT This enforcer makes sure that elements in the and sections are ordered.
PedanticPluginManagementLocationEnforcer PLUGIN_MANAGEMENT_LOCATION Enforces that only a well-defined set of POMs may declare plugin management.