google / error-prone

Catch common Java mistakes as compile-time errors
https://errorprone.info
Apache License 2.0
6.84k stars 743 forks source link

Can't compile with JDK10 / Xplugin:ErrorProne with Ant #1086

Closed don-vip closed 6 years ago

don-vip commented 6 years ago

What version of Error Prone are you using?

2.3.1

Does this issue reproduce with the latest release?

Yes

What did you do?

We have to maintain our Ant build working with Java 8 and later versions. As I saw error_prone is supposed to work with Java 10 (https://github.com/google/error-prone/issues/860#issuecomment-411463532) I gave it a try in our build:

<project xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" name="josm" default="compile-jmapviewer" xmlns:jacoco="antlib:org.jacoco.ant" xmlns:if="ant:if" xmlns:unless="ant:unless">
    <target name="init-properties">
        <property environment="env"/>
        <dirname property="base.dir" file="${ant.file.josm}"/>
        <property name="src.dir" location="${base.dir}/src"/>
        <property name="build.dir" location="${base.dir}/build"/>
        <property name="tools.dir" location="${base.dir}/tools"/>
        <property name="error_prone_ant.jar" location="${tools.dir}/error_prone_ant.jar"/>
        <property name="java.lang.version" value="1.8" />
        <!-- For Java10-specific stuff -->
        <condition property="isJava10">
            <matches string="${ant.java.version}" pattern="1[0-9]" />
        </condition>
        <!-- error_prone works differently on Java 10+, see https://github.com/google/error-prone/issues/860 -->
        <condition property="javac.compiler" value="modern" else="com.google.errorprone.ErrorProneAntCompilerAdapter">
            <isset property="isJava10"/>
        </condition>
    </target>

    <target name="init" depends="init-properties">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${dist.dir}"/>
    </target>

    <target name="compile-jmapviewer" depends="init">
        <!-- JMapViewer -->
        <javac compiler="${javac.compiler}" sourcepath="" srcdir="${src.dir}" 
            excludes="com/**,javax/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java,org/openstreetmap/gui/jmapviewer/JMapViewerTree.java,org/openstreetmap/gui/jmapviewer/checkBoxTree/**,org/openstreetmap/josm/**,org/tukaani/**,gnu/**"
            destdir="${build.dir}" target="${java.lang.version}" source="${java.lang.version}" debug="on" includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8">
            <compilerclasspath>
                <pathelement location="${error_prone_ant.jar}"/>
            </compilerclasspath>
            <compilerarg line="-XDcompilePolicy=simple" compiler="modern"/>
            <compilerarg line="-processorpath ${error_prone_ant.jar}" compiler="modern"/>
            <compilerarg value="-Xplugin:ErrorProne" compiler="modern"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:deprecation"/>
            <compilerarg value="-Xlint:dep-ann"/>
            <compilerarg value="-Xlint:divzero"/>
            <compilerarg value="-Xlint:empty"/>
            <compilerarg value="-Xlint:finally"/>
            <compilerarg value="-Xlint:overrides"/>
            <compilerarg value="-Xlint:static"/>
            <compilerarg value="-Xlint:try"/>
            <compilerarg value="-Xlint:unchecked"/>
            <compilerarg value="-XDignore.symbol.file"/>
            <compilerarg value="-Xep:CatchAndPrintStackTrace:OFF"/>
            <compilerarg value="-Xep:ReferenceEquality:OFF"/>
            <compilerarg value="-Xep:StringSplitter:OFF"/>
            <compilerarg line="-Xmaxwarns 1000"/>
        </javac>
    </target>
</project>

This build works with Java 8 and 9 by replacing the javac compiler.

What did you expect to see?

The build working on Java 10 by using the javac plugin.

What did you see instead?

javac seems happy with the new options (-XDcompilePolicy=simple, -processorpath ${error_prone_ant.jar} and -Xplugin:ErrorProne) but fails with error_prone specific options (-Xep:*):

compile-jmapviewer:
    [javac] Compiling 50 source files to C:\SVN\josm\core\build
    [javac] Using modern compiler
    [javac] Compilation arguments:
    [javac] '-d'
    [javac] 'C:\SVN\josm\core\build'
    [javac] '-classpath'
    [javac] 'C:\SVN\josm\core\build'
    [javac] '-target'
    [javac] '1.8'
    [javac] '-encoding'
    [javac] 'UTF-8'
    [javac] '-g'
    [javac] '-XDcompilePolicy=simple'
    [javac] '-processorpath'
    [javac] 'C:\SVN\josm\core\tools\error_prone_ant.jar'
    [javac] '-Xplugin:ErrorProne'
    [javac] '-Xlint:cast'
    [javac] '-Xlint:deprecation'
    [javac] '-Xlint:dep-ann'
    [javac] '-Xlint:divzero'
    [javac] '-Xlint:empty'
    [javac] '-Xlint:finally'
    [javac] '-Xlint:overrides'
    [javac] '-Xlint:static'
    [javac] '-Xlint:try'
    [javac] '-Xlint:unchecked'
    [javac] '-XDignore.symbol.file'
    [javac] '-Xep:CatchAndPrintStackTrace:OFF'
    [javac] '-Xep:ReferenceEquality:OFF'
    [javac] '-Xep:StringSplitter:OFF'
    [javac] '-Xmaxwarns'
    [javac] '1000'
    [javac] '-source'
    [javac] '1.8'
    [javac] 
    [javac] The ' characters around the executable and arguments are
    [javac] not part of the command.
    [javac] javac: invalid flag: -Xep:CatchAndPrintStackTrace:OFF
    [javac] Usage: javac <options> <source files>
    [javac] use --help for a list of possible options

BUILD FAILED
C:\SVN\josm\core\build.xml:331: Compile failed; see the compiler error output for details.
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1428)
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:350)
    at org.apache.tools.ant.Target.execute(Target.java:448)
    at org.apache.tools.ant.Target.performTasks(Target.java:469)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1370)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:36)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:460)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:142)
tbroyer commented 6 years ago

Options are passed to plugins by separating them with spaces in the same argument as the -Xplugin:

<compilerarg value="-Xplugin:ErrorProne -Xep:CatchAndPrintStackTrace:OFF …" compiler="modern" />
don-vip commented 6 years ago

Thanks a lot! I confirm it works now :)