Running aspectj-maven-plugin with the current Version 1.8.1 of AspectJ

Lately, I stumbled over a syntactically valid class, that can not be compiled by the aspectj-maven-plugin, even so it is a valid Java-7.0 class.

Using the current version (Version 1.8.1) of AspectJ solves this issue. But unfortunatly, there is no new version of the aspectj-maven-plugin available, that uses this new version of AspectJ. The last version of the aspectj-maven-plugin was released to Maven Central on December the 4th 2013 and this versions is bundeled with the version 1.7.2 of AspectJ.

The simple solution is, to bring the aspectj-maven-plugin to use the current version of AspectJ. This can be done, by overwriting its dependency to the bundled aspectj. This definition of the plugin does the trick:


<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.6</version>
  <configuration>
    <complianceLevel>1.7</complianceLevel>
    <aspectLibraries>
      <aspectLibrary>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
      </aspectLibrary>
    </aspectLibraries>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjtools</artifactId>
      <version>1.8.1</version>
    </dependency>
  </dependencies>
</plugin>

The crucial part is the explicit dependency, the rest depends on your project and might have to be adjusted accordingly:


  <dependencies>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjtools</artifactId>
      <version>1.8.1</version>
    </dependency>
  </dependencies>

I hope, that helps, folks!

Comments / Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>