Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error, annotations are only available if source level is 5.0 - AspectJ in Maven

I am trying to use the aspectj-maven-plugin in a maven project. At compile time, I get:

Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0

Yet, I set the following in my pom.xml:

<project.build.source>1.6</project.build.source>
<project.build.target>1.6</project.build.target>

I have some dependencies to:

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.6.11</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.4</version>
    </dependency>

How do I solve this issue? Thanks.

Solution

I added the following in my pom.xml and now it works:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                    <configuration>
                        <source>${project.build.source}</source>  <- Addition
                        <target>${project.build.target}</target>  <- Addition
                    </configuration>
                </execution>
           </executions>
       </plugin>
like image 661
Jérôme Verstrynge Avatar asked Sep 09 '11 11:09

Jérôme Verstrynge


2 Answers

You can explicity set the source parameter of the aspectj plugin. Docs here.

like image 147
Paul Grime Avatar answered Oct 07 '22 18:10

Paul Grime


I was able to solve this issue by adding the following to my pom:

<properties>
<project.build.java.target>1.6</project.build.java.target>
</properties>

was able to find this from this post.

like image 5
Gabriel Dimech Avatar answered Oct 07 '22 19:10

Gabriel Dimech