All warnings as errors with the Eclipse Java compiler (3.6.2)

倖福魔咒の 提交于 2019-12-12 03:34:45

问题


How do I treat warnings as errors with the Eclipse Java compiler (ECJ) 3.6.2*when running from the command-line?

Newer versions (at least, 3.8.2) have the -err:all flag, however this isn't available in 3.6.2. Do I have any other options?

I've found this question (Javac: Treat warnings as errors) which recommends the undocumented -Werror flag, but that only seems to work for javac.

Note: For various reasons completely out of my control, I must use ECJ 3.6.2. So switching to a newer version or javac is not an option (at least, not in the immediate future)!


* Also seems to be known as the "JDT Core Batch Compiler".

回答1:


I don't think there's a way to specify err:all, but there's a decent workaround:

  1. Create an eclipse project.
  2. Project > Properties > Java Compiler > Errors / Warnings.
  3. Enable project specific settings.
  4. Set everything to Error level by hand (annoying, but a one time operation).
  5. That generates a org.eclipse.jdt.core.prefs file.
  6. Use the project/.settings/org.eclipse.jdt.core.prefs file in your compile process.

Here's an example using ant:

<javac srcdir="${test-unit.dir}" destdir="${target-test-classes.dir}" 
        classpathref="test.classpath" source="1.6" target="1.6" debug="true" 
        includeAntRuntime="false" compiler="org.eclipse.jdt.core.JDTCompilerAdapter">
    <compilerclasspath location="./libs/ecj-3.7.2.jar" />
    <compilerarg line="-time -properties .settings/org.eclipse.jdt.core.prefs" />
</javac> 


来源:https://stackoverflow.com/questions/14927376/all-warnings-as-errors-with-the-eclipse-java-compiler-3-6-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!