I'm developing a multi-module project with gradle/intellij-idea, and here is the structure of my project home:
project/ sub-project-1 /main/resources sub-project-2 /main/resources data /main/resources /test/resources
As you can see I have multiple sub-projects (all java), how can I make them depend on some common resources (the "data" project, which contains no code but only resources), as well as their own separate resources?
Also it's best that the intellij-idea can pick up these dependencies with JetGradle automatically (JetGradle do just fine picking up the default gradle java project dependencies within each sub project).
Thanks a lot!
subprojects { sourceCompatibility = 11 } It adds the sourceCompatibility property to all sub-projects. This property is then used by the Gradle build Java Plugin: Java version compatibility to use when compiling Java source. Default value: version of the current JVM in use JavaVersion.
Right click on the deploy or any other task and select "Open Gradle Run Configuration..." Then navigate to "Java Home" and paste your desired java path.
The approach I took was to use project reference
sourceSets { main { resources { srcDirs += [ project(':data').sourceSets.main.resources ] } } }
UPDATE: Tested with Gradle7 and it still works. Tested with java-library plugin.
One solution is to apply the Java plugin also to the data
project, and then use regular project dependencies (e.g. dependencies { runtime project(":data") }
). However, this would require a bit of effort to prevent shipping the test resources.
Another solution is not to make data
a Gradle project but literally include its resource directories in the other two projects (sourceSets.main.resources.srcDir "../data/main/resources"; sourceSets.test.resources.srcDir "../data/test/resources"
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With