Ensure that all the Java properties defined in resources .properties files are also used in code, all properties used in code are also defined and no property is defined more than once.
- Apache's Maven Enforcer Plugin is used to apply and enforce rules on your Maven projects.
- The Enforcer plugin ships with a set of standard rules.
- This project provides an extra rule (enforceProperties) which is not part of the standard rule set.
- More extra rules can be found MojoHaus Project extra rules which are not part of the standard rule set.
Add the following to your project's pom.xml
file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.github.mikkoi.maven.enforcer.rule</groupId>
<artifactId>property-usage-rule</artifactId>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce-property-usage</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceProperties implementation="com.github.mikkoi.maven.plugins.enforcer.rule.propertyusage.PropertyUsageRule">
<!-- default: "${project.build.sourceEncoding}" -->
<sourceEncoding>UTF-8</sourceEncoding>
<!-- default: "${project.build.sourceEncoding}" -->
<propertiesEncoding>UTF-8</propertiesEncoding>
<definitionsOnlyOnce>true</definitionsOnlyOnce>
<definedPropertiesAreUsed>true</definedPropertiesAreUsed>
<usedPropertiesAreDefined>false</usedPropertiesAreDefined>
<replaceInTemplateWithPropertyName>REPLACE_THIS</replaceInTemplateWithPropertyName>
<propertyNameRegexp>([a-z0-9\-\.]{1,}?)</propertyNameRegexp>
<definitions>
<!-- The files from which to read the used properties. -->
<!-- default: src/main/resources/**/*.properties -->
<!-- file is either a path to a file or dir. -->
<!-- Patterns (wildcards) not supported at the moment. -->
<!-- When directory, all files in it are checked recursively. -->
<file></file>
</definitions>
<templates>
<!-- The usage templates. -->
<!-- default: property name (as it is in *.properties files) -->
<!-- in quotation marks -->
<template></template>
</templates>
<usages>
<!-- The files to check for the used properties. -->
<!-- default: src/main/java/**/*.java -->
<!-- file is either a path to a file or dir. -->
<!-- Patterns (wildcards) not supported at the moment. -->
<!-- When directory, all files in it are checked recursively. -->
<file></file>
</usages>
</enforceProperties>
</rules>
<!-- Fail build if rule broken. -->
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>