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

Jérôme Verstrynge picture Jérôme Verstrynge · Sep 9, 2011 · Viewed 16k times · Source

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>

Answer

Paul Grime picture Paul Grime · Sep 9, 2011

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