Alex Rivera | Logout

Maven: compile aspectj project containing Java 1.6 source

Asked 2010-04-09T20:19:28.367
22

Primary Question

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).


Update 2/21/2011: There are two equally viable solutions to this (both cases use the aspectj-maven-plugin in conjuction with the maven-compiler-plugin):

  1. Add <failOnError>false</failOnError> to the compiler plugin (thanks Pascal Thivent)
  2. Add <phase>process-sources</phase> to the aspectj compiler plugin (thanks Andrew Swan)

More info on these solutions is in the answer section. I believe solution #2 is the better approach.







Related Questions

Questions (based on failed attempts below):

  1. How do you get maven to run the aspectj:compile goal directly, without ever running compile:compile?
  2. How do you ignore the failure of compile:compile?
  3. How do you specify a custom compilerId that points to your own ajc compiler (that is make compile:compile use an aspectj compiler other than the plexus one)?*
Thanks for any and all suggestions. These are the things I've tried that have led to my problem/questions:


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

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId&
Edit
Report

1 Answer

16

Version 1.3 of the AspectJ plugin deliberately changed the default phase of its compile goal from process-sources to compile, see MASPECTJ-13. This causes follow-up problems like yours or MASPECTJ-92. To restore the previous behaviour of running ajc before javac, you just need to add a "phase" tag to the relevant "execution" tag, like this:

<execution>
    <phase>process-sources</phase> <!-- or any phase before compile -->
    <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
    </goals>
</execution>
answered 2011-02-18T05:43:26.887

Your Answer