问题
Here is my configuration of aspectj maven plugin for java 8:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.8</source>
<target>1.8</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.8</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>external project containing aspects</groupId>
<artifactId>external project containing aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies>
</plugin>
When I add a surefire plugin like below, I am able to weave the aspects on load-time.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>javaagent:${user.home}/.m2/repository/org/aspectj/aspectjweaver/1.8.7/aspectjweaver-1.8.7.jar</argLine>
</configuration>
</plugin>
To make sure that my aspect is hit, I have added println statements in it. But they are not getting shownup on the console when trying to do compile time weaving. Please help me. I dont know what I am missing in my configuration. Not able to figure out why the aspects are not getting hit.
回答1:
No issue with the configuration. The problem was, my aspects were defined as abstract with their concrete implementation in the aop.xml file. That is the reason they were not loaded at compile time. So I made them concrete aspects and it worked.
来源:https://stackoverflow.com/questions/37288263/aspectj-maven-plugin-for-java-8-is-able-to-runtime-weave-aspects-but-not-compile