Search code examples
javaintellij-ideagradle

Gradle: common resource dependency for multiple java projects


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!


Solution

  • 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").