Does Maven really honor the <source> tag in the compiler plugin?

I am working on a Java program that should be compatible with Java 5. I had @Override annotations for implemented interface methods that are allowed in Java 6 but not in 5. I use the Java 6 SDK. Eclipse correctly gives error messages in @Override when I install it in accordance with 5.0. However, my Maven build works without 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> 

Do I believe that this should lead to a build failure? Why is this not the case, and is there something I can do?

+6
java maven-2
source share
2 answers

This is actually a JDK issue, not a Maven issue. @Override annotations are not reset with the -source 1.5 to 1.6 javac flag. Go and try. The only way to make this unsuccessful, unfortunately, is to use 1.5 javac.

Sorry, hth.

EDIT
I ran into this problem myself, and I also wondered if she was really looking at the mood in the pump. Enabling debug output (-X, I suppose it was recently) will print the javac command line to standard output, and you will see that it really uses the -source 1.5 parameter.

+5
source share

As the answer, roe says you need to use the 1.5 compiler, because the JDK is not doing its job absolutely correctly. It is worth noting that you can avoid clutter by using paths, etc. configure 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> 

Then you can 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> 
+1
source share

All Articles