Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aspectj-maven-plugin and Java 7

How do I have to setup the pom.xml so the aspectj-maven-plugin uses Java 7 to compile?

When I compile with my current configuration (see below), I always get a message complaining about my use of some Java 7 specific feature, e.g.

error: multi-catch statement is not supported in -source 1.5

I use eclipse, in the project properties -> java compiler it says 1.5 for compliance level, source, target. What am I doing wrong?

A very similar question was asked here, but the solution doesn't work for me, I'm already on version 1.7.4 of org.aspectj.

The question can also be rephrased as:

How can I make maven compile my code using Java 7 and weave the aspects in?

I don't have to use the aspectj-maven-plugin. But what other way is there that works?

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.stuff</groupId>
    <artifactId>artifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
like image 309
hansi Avatar asked Oct 20 '22 17:10

hansi


1 Answers

I found a way to do it in this question. The problem seems to be that the java and aspectj compilers are not called in the order one would expect.

In short, adding <phase>process-sources</phase> did the job for me:

<executions>
 <execution>
  <phase>process-sources</phase>
  <goals>
   <goal>compile</goal>
   <goal>test-compile</goal>
  </goals>
 </execution>
</executions>
like image 152
hansi Avatar answered Oct 23 '22 11:10

hansi