title: IntelliJ tests fail, Gradle tests fine: does not recognize JSON files in 'test/resources'
body: <p>In a project I want to use some sample JSON files from src/test/resources in my test classes. The project can be found on <a href="https://github.com/kamikat/moshi-jsonapi" rel="nofollow noreferrer">https://github.com/kamikat/moshi-jsonapi</a> if you want to test it for yourself. The project setup looks like this:
  <a href="https://i.stack.imgur.com/gm8Wk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gm8Wk.png" alt="project setup"></a></p>
  
  <p>And in my tests I load the resource files like this:</p>
  
  <pre><code>public static String readResource(String resourceName) {
      Scanner scanner = new Scanner(TestResources.class.getResourceAsStream(resourceName), "UTF-8");
      return scanner.useDelimiter("\\A").next();
  }
  
  public static String getPrivateSample() {
      return readResource("/private.json");
  }
  </code></pre>
  
  <p>So far, so good. To add the *.json files to my classpath, I needed to add this to the build.gradle file:</p>
  
  <pre><code>sourceSets {
      test {
          resources {
              srcDir "resources"
              includes["**/*.json"]
          }
      }
  }
  </code></pre>
  
  <p>Now I can run <code>./gradlew test</code>, and all tests are green - great!
  But: If I run the tests from IntelliJ (Android Studio 2.2 RC1), the following happens:</p>
  
  <pre><code>java.lang.NullPointerException: source
  
      at java.util.Objects.requireNonNull(Objects.java:228)
      at java.util.Scanner.&lt;init&gt;(Scanner.java:578)
      at moe.banana.jsonapi2.TestResources.readResource(TestResources.java:8)
      at moe.banana.jsonapi2.TestResources.getPrivateSampleSerialized(TestResources.java:17)
      at moe.banana.jsonapi2.PrivateAndProtectedTest.serializePrivate(PrivateAndProtectedTest.java:58)
      at [...]
  </code></pre>
  
  <p>The problem appears to be that the JSON files are not added to the classpath when the tests run from IntelliJ. I can fix this temporarily by adding the resources as a manual dependency in the project settings, but I am looking for an automated solution.</p>
  
  <p>I already tried <a href="https://stackoverflow.com/questions/24395243/gradle-including-resources-in-tests">this</a>, <a href="https://stackoverflow.com/questions/27755843/how-to-add-test-resources-root-in-gradle-intellij">this</a> and <a href="https://stackoverflow.com/questions/25513788/intellij-cant-find-classpath-test-resource">this</a>, but nothing works.
  Some answers suggest it's a <a href="https://youtrack.jetbrains.com/issue/IDEA-128966" rel="nofollow noreferrer">bug in IntelliJ</a>, which is marked as 'fixed' - but still there is no suitable solution working for me.</p>
  
  <p>Did anyone get his test resources working correctly?</p>