本文介绍了Maven插件确保UTF-8编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果构建器注意到没有使用UTF-8编码的文件,是否有可用于使构建失败的Maven插件?
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?
推荐答案
是的,
它使用和进行编码检测。
It uses the Maven Enforcer Plugin, and juniversalchardet to do the encoding detection.
更新2016-10-20: codehaus.mojo有一个插件,它引入了一个规则。它使用进行编码检测。
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.
用法是:
<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>
这篇关于Maven插件确保UTF-8编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!