javamavenjunitchecker-framework

Checker Framework, -Xlint:all and JUnit


I'm trying to keep a project with a very clean and strict setup from the outset, including:

  1. Use of the Checker Framework.
  2. Enabling all compiler warnings and treat them as errors (-Xlint:all and -Werror).
  3. Use of JUnit.

Here are the relevant parts from Maven's pom.xml:

<dependencies>
    <!-- Annotations: nullness, etc -->
    <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>checker-qual</artifactId>
        <version>${checkerframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>jdk8</artifactId>
        <version>${checkerframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.checkerframework</groupId>
                            <artifactId>checker</artifactId>
                            <version>${checkerframework.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <annotationProcessors>
                        <!-- Add all the checkers you want to enable here -->
                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker
                        </annotationProcessor>
                    </annotationProcessors>
                    <compilerArgs>
                        <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
                        <arg>-Xlint:all</arg>
                        <arg>-Werror</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Unfortunately, as soon as I introduce a test class that uses the @Test annotation, I get the following compilation warning and thus a build error:

Warning:java: No processor claimed any of these annotations: org.junit.jupiter.api.Test

How can this warning be avoided?


Solution

  • Found a solution: this specific warning can be silenced with -Xlint:-processing:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        ...
                        <compilerArgs>
                            <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
                            <arg>-Xlint:all</arg>
                            <!-- Silence warning "No processor claimed any of these annotations". One of the
                            annotations that would trigger it is org.junit.jupiter.api.Test -->
                            <arg>-Xlint:-processing</arg>
                            <arg>-Werror</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>