在Maven构建中,如何配置Nullaway以排除测试类?

时间:2023-01-18 11:15:10

In a Maven build how do I configure Nullaway to exclude test classes? Right now it's firing on code that specifically checks that NullPointerExceptions are thrown in the right places.

在Maven构建中,如何配置Nullaway以排除测试类?现在,它正在触发代码,专门检查NullPointerExceptions是否在正确的位置抛出。

The code to be excluded lives in the customary src/test/java directory but in the same packages as the model code.

要排除的代码位于习惯的src / test / java目录中,但与模型代码位于相同的包中。

1 个解决方案

#1


-1  

NullAway is an Error Prone plugin. Error Prone works with the help of its own compiler (Maven compiler id javac-with-errorprone). I see two ways you can avoid applying Error Prone/NullAway for test classes:

NullAway是一个Error Prone插件。 Error Prone在其自己的编译器(Maven编译器id javac-with-errorprone)的帮助下工作。我看到两种方法可以避免为测试类应用Error Prone / NullAway:

  1. If all relevant classes contain the @Test annotation then you can use the -XepOpt:NullAway:ExcludedClassAnnotations=depends.on.junit.version.Test option of the NullAway Maven plugin.

    如果所有相关类都包含@Test注释,那么您可以使用NullAway Maven插件的-XepOpt:NullAway:ExcludedClassAnnotations = depends.on.junit.version.Test选项。

  2. Try to disable Error Prone by using the standard compiler when compiling Test classes by providing the standard compiler id (<compilerId>javac</compilerId>) in the maven-compiler-plugin configuration for the goal testCompile. See the accepted answer here for an example of how to provide a configuration for the test compilation.

    尝试通过在目标testCompile的maven-compiler-plugin配置中提供标准编译器ID( javac )来编译Test类时使用标准编译器来禁用Error Prone。有关如何为测试编译提供配置的示例,请参阅此处接受的答案。

#1


-1  

NullAway is an Error Prone plugin. Error Prone works with the help of its own compiler (Maven compiler id javac-with-errorprone). I see two ways you can avoid applying Error Prone/NullAway for test classes:

NullAway是一个Error Prone插件。 Error Prone在其自己的编译器(Maven编译器id javac-with-errorprone)的帮助下工作。我看到两种方法可以避免为测试类应用Error Prone / NullAway:

  1. If all relevant classes contain the @Test annotation then you can use the -XepOpt:NullAway:ExcludedClassAnnotations=depends.on.junit.version.Test option of the NullAway Maven plugin.

    如果所有相关类都包含@Test注释,那么您可以使用NullAway Maven插件的-XepOpt:NullAway:ExcludedClassAnnotations = depends.on.junit.version.Test选项。

  2. Try to disable Error Prone by using the standard compiler when compiling Test classes by providing the standard compiler id (<compilerId>javac</compilerId>) in the maven-compiler-plugin configuration for the goal testCompile. See the accepted answer here for an example of how to provide a configuration for the test compilation.

    尝试通过在目标testCompile的maven-compiler-plugin配置中提供标准编译器ID( javac )来编译Test类时使用标准编译器来禁用Error Prone。有关如何为测试编译提供配置的示例,请参阅此处接受的答案。