解决了中文乱码问题的emma-maven-plugin

用emma-maven-plugin在Maven里集成emma进行代码覆盖率测试时,如果用的官方的emma-maven-plugin的话,在java源码的字符编码和操作系统的默认字符编码不一致的情况下会汉字会出现乱码。这是因为emma-maven-plugin和emma做的不够完善,没有提供读取源码时指定字符编码的接口,而是始终采用系统默认编码来读取源文件。

我修改了emma的原代码,加入了指定字符编码的接口。用maven编译以后的jar放在附件中。

下载附件的zip文件, 解压缩,然后执行下列命令把上面的两个jar安装到本地maven库里。

mvn install:install-file -Dfile=emma-maven-plugin-1.2.0.fixed.jar -DpomFile=emma-maven-plugin-1.2.0.fixed.pom
mvn install:install-file -Dfile=emma-2.1.0.fixed.jar -DpomFile=emma-2.1.0.fixed.pom

然后在你的项目的pom.xml中加入emma-maven-plugin的配置


<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.2.0.fixed</version>
<inherited>true</inherited>
<executions>
<execution>
<id>instrument</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>emma</goal>
</goals>
<configuration>
<outputEncoding>UTF-8</outputEncoding>
<sourceEncoding>UTF-8</sourceEncoding>
</configuration>
</execution>
</executions>
</plugin>



<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.2.0.fixed</version>
<inherited>true</inherited>
</plugin>


具体可以参见附件中的pom.xml

这里和原始的emma-maven-plugin配置方法一样, 主要是注意version。

对emma和emma-maven-plugin修改的源代码在下面的链接,有兴趣可以fork。
[url=https://github.com/zjumty/Emma]https://github.com/zjumty/Emma[/url]
[url=https://github.com/zjumty/emma-maven-plugin]https://github.com/zjumty/emma-maven-plugin[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值