Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure maven to use checker-framework with error-prone? #945

Closed
originalrusyn opened this issue Oct 12, 2016 · 5 comments
Closed
Milestone

Comments

@originalrusyn
Copy link

<prerequisites>
    <maven>3.3.9</maven>
</prerequisites>

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
    <archiveClasses>true</archiveClasses>
    <!-- These properties will be set by the Maven Dependency plugin -->
    <!-- Change to jdk7 if using Java 7 -->
    <annotatedJdk>${org.checkerframework:jdk7:jar}</annotatedJdk>
    <!-- Uncomment to use the type annotations compiler. -->
    <!-- <typeAnnotationsJavac>${org.checkerframework:compiler:jar}</typeAnnotationsJavac> -->
</properties>


<build>
    <!-- for hot reload of the web application-->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <compilerId>javac-with-errorprone</compilerId>
                <forceJavacCompilerUse>true</forceJavacCompilerUse>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <annotationProcessors>
                    <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                </annotationProcessors>
                <compilerArgs>
                    <!-- location of the annotated JDK, which comes from a Maven dependency -->
                    <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
                    <!-- Uncomment the following line if using Java 7. -->
                    <arg>-J-Xbootclasspath/p:${typeAnnotationsJavac}</arg>
                    <arg>-Alint</arg>
                    <arg>-AprintErrorStack</arg>
                    <arg>-XDTA:spacesincomments</arg>
                </compilerArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.plexus</groupId>
                    <artifactId>plexus-compiler-javac-errorprone</artifactId>
                    <version>2.8.1</version>
                </dependency>
                <dependency>
                    <groupId>com.google.errorprone</groupId>
                    <artifactId>error_prone_core</artifactId>
                    <version>2.0.5</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <archive>
                    <manifestFile>${project.build.directory}/${project.build.finalName}/WEB-INF/classes/META-INF/MANIFEST.MF</manifestFile>
                </archive>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<dependencies>
    <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>checker-qual</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>checker</artifactId>
        <version>2.1.4</version>
    </dependency>
    <!-- The type annotations compiler - uncomment if desired -->
    <!-- <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>compiler</artifactId>
        <version>2.1.4</version>
    </dependency> -->
    <!-- The annotated JDK to use (change to jdk7 if using Java 7) -->
    <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>jdk7</artifactId>
        <version>2.1.4</version>
    </dependency>
</dependencies>

maven clean install:

warning: unknown enum constant ElementType.TYPE_PARAMETER
warning: unknown enum constant ElementType.TYPE_USE
warning: unknown enum constant ElementType.TYPE_PARAMETER
warning: unknown enum constant ElementType.TYPE_USE
warning: unknown enum constant ElementType.TYPE_PARAMETER
error: InvocationTargetException when invoking constructor for class org.checkerframework.checker.nullness.KeyForVisitor; Underlying cause: InvocationTargetException when invoking constructor for class org.checkerframework.checker.nullness.KeyForAnnotatedTypeFactory; Underlying cause: java.lang.ArrayStoreException: sun.reflect.annotation.EnumConstantNotPresentExceptionProxy
Exception: java.lang.reflect.InvocationTargetException; Stack trace: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

@mernst
Copy link
Member

mernst commented Oct 12, 2016

Can you provide a complete test case?

I installed the text of your report as file pom.xml in an otherwise empty directory, then ran mvn clean install.

I got the following output:

mvn clean install
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project [unknown-group-id]:[unknown-artifact-id]:1.0-SNAPSHOT (/homes/gws/mernst/tmp/foo/pom.xml) has 2 errors
[ERROR]     'groupId' is missing. @ line 3, column 109
[ERROR]     'artifactId' is missing. @ line 3, column 109
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

@originalrusyn
Copy link
Author

Can you provide a complete test case?

Please see
https://github.com/originalrusyn/credits2

@wmdietl
Copy link
Member

wmdietl commented Oct 15, 2016

Thanks for providing the test case! I can reproduce the failure in Maven. I'm trying to reproduce it on the command-line, too.
We recently modified the code that is throwing the exception. Maybe that already fixed the problem.

Alternatively, you could separate the error-prone compilation from the Checker Framework compilation into two separate Maven tasks.

@wmdietl wmdietl self-assigned this Oct 19, 2016
@mernst
Copy link
Member

mernst commented Jul 5, 2017

This may be blocked by #1224

@wmdietl
Copy link
Member

wmdietl commented Dec 1, 2019

#1224 is fixed and we have updated instructions for using Maven with the ErrorProne compiler together with the Checker Framework: https://checkerframework.org/manual/#maven
Please re-open this issue or file a new one if something doesn't work as expected.

@wmdietl wmdietl closed this as completed Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants