gpt4 book ai didi

java - 检查器框架,-Xlint :all and JUnit

转载 作者:行者123 更新时间:2023-12-04 15:52:38 28 4
gpt4 key购买 nike

我试图从一开始就保持一个非常干净和严格设置的项目,包括:

  • 使用 the Checker Framework .
  • 启用所有编译器警告并将它们视为错误( -Xlint:all-Werror )。
  • 使用 JUnit .

  • 以下是 Maven 的相关部分 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>

    不幸的是,一旦我介绍了一个使用 @Test 的测试类注释,我收到以下编译警告,因此出现构建错误:

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



    如何避免这种警告?

    最佳答案

    找到解决方案:可以使用 -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>

    关于java - 检查器框架,-Xlint :all and JUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53245938/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com