16

UPDATE: here is my maven-compiler-plugin configuration:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>

I work on a multi-project application that I build with Maven. We decided to add AspectJ so I added the following code to pom.xml in the top level project: (from the official documentation)

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.7.3</version>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>    <!-- use this goal to weave all your main classes -->
              <goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  <build>
  ...
</project>

and the following fragments to each subordinate projects:

</project>
      ...  
      <build>
        ....
           <plugins>
               ...
            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            </plugin>
         </plugins>
    </build>

        <dependencies>
          ...
         <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
         </dependency>
         ....
      </dependencies>
     ...  
 </project>

Somehow this modification has overridden the Java version I use. If I run build I get multiple errors like this:

Syntax error, annotations are only available if source level is 1.5 or greater

That gives me the suspicion that my Java version (originally 1.6) was somehow reverted to 1.4. I did nothing - at least not knowingly - that could influence the Java version, so I suspect that the above mentioned AspectJ related code is responsible for the change.

My question is how can AspectJ change the Java version and what should I do to fix this problem. Or do I misunderstand something completely and am I on the wrong track?

gvlasov
  • 18,638
  • 21
  • 74
  • 110
Sanyifejű
  • 2,610
  • 10
  • 46
  • 73

5 Answers5

45

I think the problem is with the default source, target and complianceLevel settings of the aspectj-maven-plugin (according to the documentation linked previously, 1.4, 1.2 and 1.4 respectively). You should set these explicitly in your parent pom:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.5</version>
            <!-- new configuration is here -->
            <configuration>
                <complianceLevel>1.6</complianceLevel>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
<build>
DB5
  • 13,553
  • 7
  • 66
  • 71
  • 2
    There is logic in what you say. But now I got a different(?) kind of error:"error Missing message: configure.incompatibleComplianceForSource in: org.aspectj.ajdt.ajc.messages error no sources specified" – Sanyifejű Feb 04 '14 at 11:46
  • 1
    It seems you've hit this issue: http://jira.codehaus.org/browse/MASPECTJ-125 Adding the following configuration parameter in your pom should (hopefully) solve the problem: `1.6` – DB5 Feb 04 '14 at 11:54
  • I don't yet know whether it solved 'all' my problem or not, but the build now completes and for that you certainly deserve your answer to be accepted.Thank you. – Sanyifejű Feb 04 '14 at 12:31
  • 1
    Just to clarify, it seems to me that those actually need to be the same, so if you used a property for the compile plugin, e.g. "project.build.targetJdk" or something like that, I would recommend to use that property in here in all three places too, e.g. ${project.build.targetJdk} – mac Mar 24 '15 at 17:50
1

I was missing

<complianceLevel>${java.level}</complianceLevel>

in my pom.xml

Oscar H
  • 104
  • 5
0

If you don't have define the version, the compiler plugin assumes that your Java source conforms to Java 1.3 and that you are targeting a Java 1.1 JVM.

Maybe, you should define it:

http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

0

You can find last versions of dependecy and plugin for aspectj.

Efthymis
  • 1,326
  • 11
  • 13
egemen
  • 779
  • 12
  • 23
0

I was missing the java version with jdk version at the top of my pom properties.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.2</version> <!-- 1.5 dint work for me -->
    <dependencies>
        <!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>process-sources</phase> <!-- or any phase before compile -->
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <outxml>true</outxml>
        <source>${jdk.version}</source>  <!-- I was missing this -->
        <target>${jdk.version}</target>  <!-- jdk.version property -->
    </configuration>
</plugin>

and at the top of my pom.xml I had set jdk.version property like,

<properties>
    <jdk.version>1.7</jdk.version>
</properties>
Lucky
  • 16,787
  • 19
  • 117
  • 151