Maven builds project with Java 1.6 even if 1.5 is specified
Possible Duplicate:
Java version mismatch in Maven
I have a project which is configured to use Java 1.5 with maven:
mvn help:effective-pom
...
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
...
My machine has Java 1.6 installed, and Maven is using it:
mvn -v
...
Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100)
Java version: 1.6.0_21
I have imported the project into Eclipse (using mvn eclipse:eclipse
), and it is building it with Java 1.5, as specified in the POM.
Now if I mark an interface implementation method with @Override
, which is disallowed in Java 1.5 but supported in Java 1.6, then Maven will build the project without errors, but Eclipse will mark the annotation as a compile-time error and refuse to build the project.
How can I either get Maven to really compile the project with Java 1.5, or get Eclipse to compile the project using the same settings as Maven?
It seems that newer versions of the JDK 1.5 ignore the @Override
if it is in an interface implementation method: https://stackoverflow.com/a/2336850/256245 I guess that JDK 1.6 does the same if it is compiling using target 1.5. That´s the reason Maven does not complain about it.
To check if Maven is really compiling to Java 1.5, you should use Animal Sniffer Plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>check-java15-sun</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java15-sun</artifactId>
<version>1.0</version>
</signature>
</configuration>
</execution>
</executions>
</plugin>
Since Eclipse have its own compiler implementation, I guess you would have to remove the @Override
annotation from interface implementation methods to make him happy. The removal will not do any harm since the annotation was being ignored by the JDK.