Test not finding resource file, works from gradle command line - but not IDE

Any ideas why this works from gradle but, but when I run “grade idea” and execute it can’t find the resource?

Here is the code:

void testBlah(){
        def stream = getClass().getClassLoader().getResourceAsStream("/database.json")
          URL url = this.getClass().getResource("/database.json");
        assert url != null
        File json = new File(url.getFile());
        assert json != null
        println "phil"
    }

Thanks

Make sure IntelliJ is set up (somewhere under Preferences) to copy ‘.json’ resources to the output directory. IntelliJ 13+ also has the concept of (test) resource directories, but that’s not yet supported by ‘gradle idea’. On the other hand, I think that ‘gradle idea’ automatically puts Gradle output dirs on the IDE class path (double-check in module dependencies dialog), so maybe the problem is somewhere else.

this did solve the problem, thanks!

Who owns the idea plugin at this point? gradle or jetbrains? it seems like this is something that should be handled by the plugin to me. Actually it seems like there should be a module level setting to use gradle resources, the patterns that copy resource seems odd to me.

The plugin that’s applied with ‘apply plugin: ‘gradle’’ is part of Gradle. The IDE integration that’s part of IntelliJ is an alternative to the ‘gradle idea’ file generation approach. ‘apply plugin: ‘gradle’’ will have to be used in any case.

Actually it seems like there should be a module level setting to use gradle resources

That’s the new IntelliJ 13 concept I talked about.