Fork me on GitHub

Require Encoding

This rule checks files for a required encoding and fails if the guessed encoding doesn't match the required one.

Note that this rule uses icu4j to guess the source encoding of a file. Use of US-ASCII is hard to detect and should not be used as a required encoding.

The following parameters are supported by this rule:

  • encoding - Required encoding. Default value ${project.build.sourceEncoding}.
  • includes - List of files to include, separated by comma or pipe
  • excludes - List of files to exclude, separated by comma or pipe
  • useDefaultExcludes - enable SCM file exclusions, enbled by default.
  • failFast - Should the rule fail after the first error or should the errors be aggregated. Default true.

Sample Plugin Configuration:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.0</version> <!-- find the latest version at http://maven.apache.org/plugins/maven-enforcer-plugin/ -->
        <executions>
          <execution>
            <id>require-utf-8</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireEncoding>
                  <encoding>UTF-8</encoding>
                  <includes>src/main/resources/**,src/test/resources/**</includes>
                </requireEncoding>
              </rules>
              <fastFail>false</fastFail>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.0-beta-6</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Trademarks

Apache, Apache Maven, Maven and the Apache feather logo are trademarks of The Apache Software Foundation.