【问题标题】:Jacoco code coverage affected by AspectJ compile time weaving受 AspectJ 编译时编织影响的 Jacoco 代码覆盖率
【发布时间】:2016-01-14 17:41:08
【问题描述】:
我正在使用 maven 构建我当前的项目。我有 Jacoco 用于代码覆盖和 aspectJ 用于编译时编织我的方面。
现在我正面临 aspectJ 编织代码影响代码覆盖率的问题。
当我们不编织代码时它是 100%,但是当我们使用 aspectJ 时它会严重下降到 1/4。有什么指点吗?
【问题讨论】:
标签:
maven
code-coverage
aspectj-maven-plugin
jacoco-maven-plugin
【解决方案1】:
@A。迪马特奥
我只是想分享我所做的解决方法,我没有找到任何合适的解决方案来解决这个问题。所以基本上 jacoco 做了什么,它在测试阶段完成后计算你编译的类的覆盖率,并且 aspectj 编译器在 weaved 中编译这些类。所以在编织之前,我只需要将我的编译类放在某个地方,这样我的项目就有两个类(编译和编织一个。)。所以我把它们放在一个单独的目录中,这样jacoco就可以从那里计算覆盖率。在pom.xml中添加
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/classesForSonar">
<fileset dir="${project.build.directory}/classes"
includes="**/*" />
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
它对我有用,你可以看看我如何实现编译时编织
implement compile time weaving with spring boot and aspectj
如果有人找到更好的解决方案,请发布。永远感激。 :)