3

我正在使用 Maven 来构建我当前的项目。我有 Jacoco 用于代码覆盖和 aspectJ 用于我的方面的编译时编织。

现在我面临的问题是 aspectJ 编织了影响代码覆盖率的代码。

当我们不编织代码时它是 100%,但是当我们使用 aspectJ 时它会严重下降到 1/4。任何指针?

4

1 回答 1

1

@一种。Di Matteo,我只是想分享我所做的解决方法,我没有找到任何合适的解决方案来解决这个问题。所以基本上 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>

它对我有用,对于我如何实现编译时编织,您可以查看 使用 spring boot 和 aspectj 实现编译时编织

如果有人找到更好的解决方案,请发布它。永远感激。:)

于 2017-01-18T10:46:54.807 回答