Skip to content

Maven Enforcer Plugin rule: 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.

License

mikkoi/maven-enforcer-property-usage

Repository files navigation

maven-enforcer-property-usage

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.

Maven Enforcer

Links

Quick Start

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>

About

Maven Enforcer Plugin rule: 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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages