Skip to content
Advertisement

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 {

  @Test
  public void testNull() {
    doNothing(null);
  }

  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?

Advertisement

Answer

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
  }
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement