AspectJ compiler fails because project is not javapathpath compatible package

My aspectj classes are not compiled, even though they are annotated with @Aspect and are in extension files .aj.

This project is an archetype of Maven JBoss AS 7 EAR.

[INFO] --- aspectj-maven-plugin:1.4:compile (default-cli) @ hms --- [WARNING] Not executing aspectJ compiler as the project is not a Java classpath-capable package [INFO] --- aspectj-maven-plugin:1.4:compile (default-cli) @ hms-ejb --- [WARNING] bad version number found in C:\Users\Oh Chin Boon\.m2\repository\org\aspectj\aspectjrt\1.5.4\aspectjrt-1.5.4.jar expected 1.6.11 found 1.5.4 [WARNING] advice defined in sg.java.hms.aspect.AbstractLoggingAspect has not been applied [Xlint:adviceDidNotMatch] [WARNING] advice defined in sg.java.hms.aspect.DefaultLoggingAspect has not been applied [Xlint:adviceDidNotMatch] [WARNING] advice defined in sg.java.hms.aspect.AbstractLoggingAspect has not been applied [Xlint:adviceDidNotMatch] 

EDIT: pom.xml snippet

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> <executions> <execution> <phase>process-sources</phase> <goals> <goal>compile</goal> <!-- use this goal to weave all your main classes --> </goals> </execution> </executions> </plugin> 
+4
source share
2 answers

Somehow you are referencing aspectj 1.5.4, but your source and target levels are 1.6. AspectJ 1.5.x is oriented only to Java 1.5. You need to explicitly specify AspectJ 1.6. Something like this should work in the dependency section:

 <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.12</version> </dependency> 
+5
source

I just got down to this problem, it was my scenario: Here is my mojo config plugin:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.7</version> <configuration> <source>1.7</source> <target>1.7</target> <complianceLevel>1.7</complianceLevel> <verbose>true</verbose> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> 

And my dependency on Aspectj:

 <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.5</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.5</version> </dependency> 

When compiling (maven install), I notice this message:

 [INFO] --- aspectj-maven-plugin:1.7:compile (default) @ com.wu.bishopframework --- Downloading: …aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.pom Downloaded: …aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.pom (1021 B at 2.3 KB/sec) Downloading: …aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.jar Downloaded: …aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.jar (10897 KB at 141.7 KB/sec) [INFO] No modifications found skipping aspectJ compile 

Then I received this message:

 [WARNING] bad version number found in C:\Users\mavargas\.m2\repository\org\aspectj\aspectjrt\1.8.5\aspectjrt-1.8.5.jar expected 1.8.2 found 1.8.5 

The solution was simple, just add aspectjtools dependency inside the plugin, as shown below:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.7</version> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>1.8.5</version> </dependency> </dependencies> <configuration> <source>1.7</source> <target>1.7</target> <complianceLevel>1.7</complianceLevel> <verbose>true</verbose> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> 

This fixed the problem.

Hope this helps someone cross in the same situation ...

0
source

Source: https://habr.com/ru/post/1391678/


All Articles