Intellij Resource files not found
Answered
I have a Gradle-build library which loads its configuration from file src/main/resources/config.properties the following way:
var res=getClass().getResource("config.properties");
Now, I have a Application, which is non-Gradle built and has a module dependency to my library.
When executing my Application, the library cannot load the resources file (always null).
In the background, Intellij puts classes into build/classes and resources to build/resources folder. But when executing my application, the classpath only consists of the build/classes directory and is missing the build/resources part. How can this be fixed?
Please sign in to leave a comment.
How do you configure dependencies between these modules?
What run configuration do you use?
Basically, I will repeat my answer at https://stackoverflow.com/q/74548294/2000323 - the best option would be to set up this as a single multi-module Gradle project. Please check the Gradle's documentation: https://docs.gradle.org/current/userguide/multi_project_builds.html
Since the library module is built by Gradle but build and run the application not using Gradle - it uses different paths for resources.
Sorry, but that's not possible for my application somehow. My Application consists of a (fairly big) multi-project Gradle project and a (also big) Ant project. The ant project has dependencies to these Gradle modules, where resources are loaded as explained above.
The root problem is, that when adding a dependency in Intellij IDEA, Intellij doesnt correctly add the build/resources dir to the classpath.