Add the following in the <plugins> list of your project’s pom file:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.4.1</version> <dependencies> <dependency> <groupId>com.github.mikkoi.maven.enforcer.rule</groupId> <artifactId>char-set-encoding-rule</artifactId> <version>1.0.1-SNAPSHOT</version> </dependency> </dependencies> <executions> <execution> <id>enforce-encoding-utf8</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <require-UTF8-Encoding implementation="com.github.mikkoi.maven.plugins.enforcer.rule.charsetencoding.CharacterSetEncodingRule"> <!-- Validate files against this encoding --> <requireEncoding>UTF-8</requireEncoding> <!-- Which dirs to scan. --> <directory>src</directory> <!-- Exclude files with names matching regex below --> <excludeRegex>^.*\.(gif|jpg|png)$</excludeRegex> <!-- Include files with names matching regex below --> <includeRegex>^.*\.java$</includeRegex> </require-UTF8-Encoding> </rules> <!-- Fail build if wrong encoding encountered. --> <fail>true</fail> </configuration> </execution> </executions> </plugin>
To know more about plugin’s configuration and parameters check the mojo page.