用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的配置
具体可以参见附件中的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]
我修改了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]