Skip to content

Commit

Permalink
Fix problem by applying AspectJ LTW before JaCoCo
Browse files Browse the repository at this point in the history
Simply reversing the order of Java agents on the Surefire command line
avoids the AspectJ weaver having to deal with JaCoCo-generated code. The
other way around makes more sense anyway, because JaCoCo wants to
measure the coverage for aspect-enhanced code.
  • Loading branch information
kriegaex committed Jan 5, 2022
1 parent a1ba93f commit 487552b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pom.xml
Expand Up @@ -31,11 +31,14 @@
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
<!-- TODO: Remove after SUREFIRE-1809, SUREFIRE-1882 are fixed in M6 (M6-SNAPSHOT test with JDK 14 was OK) -->
<useModulePath>false</useModulePath>
<!-- AspectJ Weaver needs access to java.base/java.lang on JDK 16+ -->
<!--
AspectJ Weaver needs access to java.base/java.lang on JDK 16+.
'@{argLine}' contains the JaCoCo agent parameters. Make sure it is applied after AspectJ.
-->
<argLine>
@{argLine}
--add-opens java.base/java.lang=ALL-UNNAMED
-javaagent:${user.home}/.m2/repository/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
@{argLine}
</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/de/scrum_master/app/MyAspect.java
Expand Up @@ -6,11 +6,7 @@

@Aspect
public class MyAspect {
@Before(
"execution(* *(..)) && !within(MyAspect)"
+ " && !execution(* *..$jacoco*(..))"
//+ " && within(de.scrum_master..*)"
)
@Before("execution(* *(..)) && !within(MyAspect)")
public void myAdvice(JoinPoint joinPoint) {
System.out.println(joinPoint);
}
Expand Down

0 comments on commit 487552b

Please sign in to comment.