[英]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-2021