Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 556
Nolequen Avatar asked Jan 30 '18 08:01

Nolequen


Video Answer


2 Answers

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
  }
like image 130
Nolequen Avatar answered Oct 17 '22 05:10

Nolequen


Try adding the following to your dependencies. It worked for me.

compile 'org.jetbrains:annotations:13.0'
like image 25
N. Aird Avatar answered Oct 17 '22 04:10

N. Aird