[英]Does Maven really honor the tag in the compiler plugin?

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:

我正在研究一个应该与Java 5兼容的Java程序。我对Java 6中允许的实现接口方法进行了@Override注释,但是在5中没有。我使用的是Java 6 SDK。当我将其设置为5.0合规性时,Eclipse正确地在@Override上提供错误消息。但是,我的Maven构建在我的POM中使用以下设置运行时甚至没有警告:


Am I correct in expecting that this should actually make the build fail? Why doesn't it, and is there something I can do?


2 个解决方案


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.

这实际上是一个JDK问题,而不是Maven问题。 @Override注释没有使用-source 1.5标志失败到1.6 javac。继续尝试。令人遗憾的是,让它失败的唯一方法是使用1.5 javac。

Sorry, HTH.

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.

编辑我自己遇到了这个问题,我也想知道它是否真的在看pom中的设置。打开调试输出(-X我相信,不久前)会将javac命令行打印到标准输出,你会发现它确实使用了-source 1.5参数。


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:



You can then specify the path to the compiler in your project or settings.xml





粤ICP备14056181号  © 2014-2020