Maven插件确保UTF-8编码? [英] Maven plugin to ensure UTF-8 Encoding?

查看:136
本文介绍了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?

推荐答案

是的, https://github.com/mikedon/encoding-enforcer

它使用 Maven Enforcer插件 juniversalchardet 进行编码检测。

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

更新2016-10-20: codehaus.mojo有一个执行者规则插件,它引入了一个 requireEncoding 规则。它使用 ICU4J 进行编码检测。

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编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆