Maven to provide UTF-8 encoding?

Is there a Maven plugin that I can use to crash my build if the builder notices a file that is not encoded using UTF-8?

+6
maven encoding maven-plugin utf-8
source share
2 answers

Yes there is https://github.com/mikedon/encoding-enforcer

It uses the Maven Enforcer Plugin and juniversalchardet to perform encoding detection.

UPDATE 2016-10-20: org.codehaus.mojo has an extra-enforcer-rules plugin that introduces requireEncoding . It uses ICU4J to detect encoding.

Using:

<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> 
+5
source share

A good choice when making Maven - no doubt you'll be a full envelope soon! :)

You might want to check out the Maven law enforcement plugin . To get started, you can use the requireProperty rule to make sure the project.build.sourceEncoding property is set to UTF-8.

As for checking the files themselves (i.e. checking whether someone made a file other than Unicode), you can implement your own rule for the force launch plugin. When this rule is fulfilled, you will need to read all the resources in the project and find some encoding detection method for each (for example, iconv).

+4
source share

All Articles