Skip to content

Gradle build ignores Jetbrains annotations

Let’s say we have the following test code:

import org.jetbrains.annotations.NotNull;
import org.junit.Test;

public class NullTest {

  public void testNull() {

  private @NotNull String doNothing(@NotNull String value) {
    return value;

The test will pass when running gradle test directly or if IDEA delegates the action to gradle. But it will fail with IllegalArgumentException: Argument for @NotNull parameter 'value' must not be null exception if it runs using IDEA runner (not delegated to gradle).

The question is: how to fail the test running it with gradle?



The easiest solution I have found is to apply org.jetbrains.intellij plugin. Because among other things this plugin “patches compile tasks to instrument code with nullability assertions”.

  apply plugin: 'org.jetbrains.intellij'

  intellij {
    instrumentCode = true
    downloadSources = false