0

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.

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

2 Answers2

0

You can exclude the test sources path from Errorprone checks (including Nullaway) like so:

<compilerArgs>
  <arg>-Xep:NullAway:ERROR</arg>
  <arg>-XepOpt:NullAway:AnnotatedPackages=[...]</arg>
  <arg>-XepExcludedPaths:.*/src/test/java/.*</arg>
</compilerArgs>
Christian Brüggemann
  • 2,152
  • 17
  • 23
-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:

  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.

  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.

Ralf
  • 6,735
  • 3
  • 16
  • 32