Maven真的很尊重编译器插件中的标签吗?

[英]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中使用以下设置运行时甚至没有警告:

    <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?

我是否正确期望这实际上会使构建失败?为什么不呢,有什么我可以做的吗?

2 个解决方案

#1


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.

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.

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

#2


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:

正如roe的回答所说,你需要使用1.5编译器,因为JDK没有完全正确地完成它的工作。值得指出的是,你可以通过调整maven-compiler-plugin配置来使用特定的编译器来避免弄乱路径等:

<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

然后,您可以在项目或settings.xml中指定编译器的路径

<properties>
  <JAVA_1_5_HOME>/path/to/1.5jdk</JAVA_1_5_HOME>
</properties>
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2009/07/28/7202014406f57e6124ed85a33f8a200d.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告