I have the following gradle.build:
apply plugin: 'war'
version = '1.0'
repositories {
mavenCentral()
}
war {
archiveName = 'querytags.war'
}
dependencies {
...
testCompile 'junit:junit:4.+'
}
test {
systemProperties 'db.user': 'root'
...
}
My directory structure is pretty standard:
src/main/java/[allMySourceCode].java
src/main/resources/
src/test/java/[UnitTestFiles].java
src/test/resources/testData.json
I’m using JerseyTest and Grizzly to unit test my WAR. In the unit test, I want to load the testData.json file (which gets placed in build/resources/test/ ). I use the following code to do so:
String resource = "/testData.json";
String fileName = UnitTests.class.getClassLoader().getResource(resource).getFile();
try (BufferedReader reader = new BufferedReader(new FileReader(fileName)))
{ ... }
But the getResource() call is returning null. Is there a setting in gradle that I need to use to allow getResources() to scan that directory? I tried adding the following to my build.gradle file, but it didn’t help:
sourceSets {
test {
output.resourcesDir = "build/resources/test"
}
}