Is there a Maven plugin I can use to fail my build if the builder notices a file that is not encoded with UTF-8?
Yes, there is https://github.com/mikedon/encoding-enforcer
It uses the Maven Enforcer Plugin, and juniversalchardet to do the encoding detection.
UPDATE 2016-10-20: org.codehaus.mojo has an extra-enforcer-rules plugin which introduces a requireEncoding rule. It uses ICU4J for the encoding detection.
Usage is:
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<!-- find the latest version at http://maven.apache.org/plugins/maven-enforcer-plugin/ -->
<version>1.0</version>
<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>
<!-- find the latest version at http://www.mojohaus.org/extra-enforcer-rules/ -->
<version>1.0-beta-6</version>
</dependency>
</dependencies>
</plugin>
Good choice on adopting Maven - no doubt you'll soon be a total convert! :)
You may want to look at the Maven enforcer plugin. As a start you could use the requireProperty
rule to ensure that the project.build.sourceEncoding
property is set to UTF-8.
As for checking the actual files themselves (i.e. checking whether someone has committed a non-unicode file), you could implement your own custom rule for the enforcer plugin. When this rule is executed, you'd need read all the resources in the project and find some method of detecting the encoding for each (e.g. iconv).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With