Maven: compile aspectj project containing Java 1.6 source

Posted by gmale on Stack Overflow See other posts from Stack Overflow or by gmale
Published on 2010-04-09T20:19:28Z Indexed on 2010/04/09 20:23 UTC
Read the original article Hit count: 540

Filed under:
|
|

What I want to do is fairly easy. Or so you would think. However, nothing is working properly.

Requirement: Using maven, compile Java 1.6 project using AspectJ compiler.

Note: Our code cannot compile with javac. That is, it fails compilation if aspects are not woven in (because we have aspects that soften exceptions).

Questions (based on failed attempts below): Either 1) How do you get maven to run the aspectj:compile goal directly, without ever running compile:compile? 2) How do you specify a custom compilerId that points to your own ajc compiler?

Thanks for any and all suggestions. These are the things I've tried that have let to my problem/questions:

Attempt 1 (fail): Specify aspectJ as the compiler for the maven-compiler-plugin:

org.apache.maven.plugins maven-compiler-plugin 2.2 1.6 1.6 aspectj org.codehaus.plexus plexus-compiler-aspectj 1.8

This fails with the error:

org.codehaus.plexus.compiler.CompilerException: The source version was not recognized: 1.6

No matter what version of the plexus compiler I use (1.8, 1.6, 1.3, etc), this doesn't work. I actually read through the source code and found that this compiler does not like source code above Java 1.5.

Attempt 2 (fail): Use the aspectJ-maven-plugin attached to the compile and test-compile goals:

org.codehaus.mojo aspectj-maven-plugin 1.3 1.6 1.6 compile
test-compile

This fails when running either:

mvn clean test-compile
mvn clean compile

because it attempts to execute compile:compile before running aspectj:compile. As noted above, our code doesn't compile with javac--the aspects are required. So mvn would need to skip the compile:compile goal altogether and run only aspectj:compile.

Attempt 3 (works but unnacceptable):

Use the same configuration above but instead run:

mvn clean aspectj:compile

This works, in that it builds successfully but it's unacceptable in that we need to be able to run the compile goal and the test-compile goal directly (m2eclipse auto-build depends on those goals). Moreover, running it this way would require that we spell out every goal we want along the way (for instance, we need resources distributed and tests to be run and test resources deployed, etc)

© Stack Overflow or respective owner

Related posts about maven-2

Related posts about aspectj