Prabha_Catalina
Prabha_Catalina

Reputation: 71

Jacoco code coverage affected by AspectJ compile time weaving

I am using maven to build my current project. I have Jacoco for code coverage and aspectJ for compile time weaving for my aspects.

Right now I am facing the issue where aspectJ weaved code affecting the code coverage.

It is 100% when we don't weave the code but it goes down badly to 1/4 when we use aspectJ. Any pointers?

Upvotes: 3

Views: 1057

Answers (1)

Prabha_Catalina
Prabha_Catalina

Reputation: 71

@A. Di Matteo, I just wanted to share the workaround which I have done, I didn't got any appropriate solution to this problem. So basically what jacoco does, its calculate the coverage of your compiled classes after the test phase completed, and aspectj compiler compiled those classes in weaved one. so before weaving, I just need to place my compile classes to some place, so that my project have both the classes(compiled and weaved one.). So I put them in a separate directory, so that jacoco can calculate coverage from there.add in 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>

Its work for me, for how I implement compile time weaving you can look implement compile time weaving with spring boot and aspectj

If anyone found a better solution please post it.Always appreciated. :)

Upvotes: 1

Related Questions