JaCoCo can not instrument classes which is already instrumented by Jmockit

Here is what I have: 

1) Sonar 3.5 which uses JaCoCo as coverage tool. 

2) Jmockit lib to perform testing with use of mocks. 

3) Build process automized with maven.

  • Jmockit seems to instrument classes it need.
  • JaCoCo can not instrument classes which is already instrumented by Jmockit and spits out a HUGE amount of exceptions, saying that it's impossible to instrument class, which were already instrumented. However Sonar seems to have a valid output for such a scenario.
    So first question is: can I somehow suppress such an exceptions? It is really critical because the size of the log file on our CI system achieves 50Mb (!), which is not acceptable. A lot of free space is just eaten up by such a logs on our CI machine.


Here are the exceptions I've got:

java.lang.instrument.IllegalClassFormatException: Error while instrumenting class app/MyClass.
Caused by: java.lang.IllegalStateException: Class app/MyClass is already instrumented.

Assuming that suppression of such an exceptions is impossible I investigated it a little bit and found out that JaCoCo (a tool, which Sonar uses and a tool, which can't instrument already instrumented classes) have such a mode as  offline instrumentation  (AFAIK Sonar neither support this  offline instrumentation  or can suppress such a warnings). This thing is designed to be used exactly for such a cases. So I tried to set up JaCoCo as a plugin in maven, but I failed to do this cause JaCoCo can't find some execution file. When I'm running  mvn clean install  the following error pops up:


[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:report (report) @ webservice-mws --- 

[INFO] Skipping JaCoCo execution due to missing execution data file

解决方法:
在jacoco 中添加:

<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
  <excludes>
      <exclude>com.cloud.generated.*</exclude>
  </excludes>
  <skip>${jacoco.skip.instrument}</skip>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

不然只能使用  
Cobertura 插件,因为jacoco和 mock存在 很多不兼容的地方。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值