15

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>
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • @Paul No I did not. Now it works. If you create a solution, I'll approve it. Thanks. – Jérôme Verstrynge Sep 09 '11 at 12:08
  • Also, I needed the addition of the complianceLevel configuration argument as well. See more here: http://stackoverflow.com/questions/21548548/adding-aspectj-to-pom-xml-changed-java-version-with-maven-why – josh-cain Feb 09 '15 at 13:18

3 Answers3

8

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

Efthymis
  • 1,326
  • 11
  • 13
Paul Grime
  • 14,970
  • 4
  • 36
  • 58
5

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.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Gabriel Dimech
  • 699
  • 5
  • 10
4

Check this page and I see a "complianceLevel" configuration property in that example; setting that to 1.5 or 1.6 might do the trick (since they have a minimum of 1.4, I'm guessing that's the default).

kenorb
  • 155,785
  • 88
  • 678
  • 743
Yhn
  • 2,785
  • 2
  • 13
  • 10