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!

aspectj-maven-plugin can not compile valid Java-7.0-Code

I stumbled over a valid construction, that can not be compiled by the aspectj-maven-plugin:


class Outer
{
  void outer(Inner inner)
  {
  }

  class Inner
  {
    Outer outer;

    void inner()
    {
      outer.outer(this);
    }
  }
}

This code might look very useless.
Originally, it Inner was a Thread, that wants to signal its enclosing class, that it has finished some work.
I just striped down all other code, that was not needed, to trigger the error.

If you put the class Outer in a maven-project and configure the aspectj-maven-plugin to weave this class with compliance-level 1.6, you will get the following error:


[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.6:compile (default-cli) on project shouter: Compiler errors:
[ERROR] error at outer.inner(this);
[ERROR] 
[ERROR] /home/kai/juplo/shouter/src/main/java/Outer.java:16:0::0 The method inner(Outer.Inner) is undefined for the type Outer
[ERROR] error at queue.done(this, System.currentTimeMillis() - start);
[ERROR] 

The normal compilation works, because the class is syntactically correct Java-7.0-Code.
But the AspectJ-Compiler (Version 1.7.4) bundeled with the aspectj-maven-pluign will fail!

Fortunately, I found out, how to use the aspectj-maven-plugin with AspectJ 1.8.3.

So, if you have a similar problem, read on…