IntelliJ can't find classpath test resource
I managed to get it working better by creating a test-resources
directory parallel to the test
directory (!).
Still seeing intermittent problems with this, though. Those times, it's possible to open the IntelliJ project settings and define the test resources as source instead (the Gradle project will remain unchanged).
Must be an IntelliJ bug, as I've experienced the same thing in Android Studio.
EDIT:
I found a workaround to the issue.
Add the following at the end of the Gradle config (and specify your test resources path):
task copyTestResources(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources
I face a similar issue with IntelliJ 14. Despite having the necessary files in my resources folder and ensuring that the folder is specified as a resource in the module settings, IntelliJ intermittently fails to load my files onto the classpath.
One workaround is to add the required folder as a dependency for the module in the module settings.
First, click on the "+" button to add a new dependency.
Then, select the folder you wish to add to the classpath.
Then select the "classes" option.
Once that is done, re-build your module once and hopefully that should do the trick.
Ideally this should not at all be an issue. All files in the resource folder should directly be put in the classpath. However, every IDE has it's quirks.
When I was running into the same issue, it worked for me to once unmark the resources directory as resources root and then mark it again as resources root:
- Right click on resources folder > Mark directory as ... > Unmark as Resources Root
- Right click on resources folder > Mark directory as ... > Test Resources Root