I work on a Java program that should be compatibe with Java 5. I had @Override
annotations on implemented interface methods which is allowed in Java 6, but not in 5. I use a Java 6 SDK. Eclipse correctly gives error messages on the @Override
when I set it to 5.0 compliance. My Maven build, however, runs without even a warning, using the following settings in my POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
Am I correct in expecting that this should actually make the build fail? Why doesn't it, and is there something I can do?
This is actually a JDK problem, not a Maven problem. The @Override annotation is not failing with a -source 1.5 flag to to a 1.6 javac. Go ahead and try it. The only way to make it fail, is, unfortunately, to use a 1.5 javac.
Sorry, HTH.
EDIT
I ran into this problem myself, and I also wondered if it's actually looking at the setting in the pom. Turning on debug output (-X I believe, was a while ago) will print the javac command line to the standard output, and you'll see that it is indeed using the -source 1.5 parameter.
As roe's answer says you need to use a 1.5 compiler because the JDK isn't doing its job quite right. It's worth pointing out that you can avoid messing about with paths etc. by tweaking the maven-compiler-plugin configuration to use a specific compiler:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_5_HOME}/bin/javac</executable>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
...
</plugins>
You can then specify the path to the compiler in your project or settings.xml
<properties>
<JAVA_1_5_HOME>/path/to/1.5jdk</JAVA_1_5_HOME>
</properties>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With