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".
I don't think there's a way to specify err:all, but there's a decent workaround:
- Create an eclipse project.
- Project > Properties > Java Compiler > Errors / Warnings.
- Enable project specific settings.
- Set everything to Error level by hand (annoying, but a one time operation).
- That generates a org.eclipse.jdt.core.prefs file.
- 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>