1

I have the following project:

-> root
->->common
->->server
->->client

I want the server and client projects to both access files from the same resource folder.

My root's build.gradle looks like the following:

apply plugin: 'java'

allprojects {
    apply plugin: 'java'
    apply plugin: 'idea'
}

subprojects {
    repositories {
        mavenCentral()
    }

    dependencies {
        testCompile 'junit:junit:4.8.1'
    }
}

The multi-project system works and I have no issues with it. I have found resources for implementing resource folders but they're only at a per-project level.

I'd appreciate any insight and help in this. :)

2 Answers2

2

If you have resources you want shared across projects you should create a library for those resources, and have each project depend on that library. Take a look at the Android documentation on library modules.

Also, take a look here for an example of how to add a project dependency to your Gradle build script.

Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
0

In case you prefer not to have another artifact then another option would be to merge the client/server code with the common code before building (e.g. $buildDir/src) and pointing the srcDir to this location. In order to do this:

  1. Add a prepareSources task of type Copy that will copy all relevant sources both from client/server and common into alternative src/main folder (e.g. under $project.buildDir/src)

  2. Rename the src/main folder in the server/client modules to something else. This is needed as the java plugin automatically includes this folder in srcDir while we want to take these sources from the merged sources location.

  3. Make compileJava and processResources dependent on the new prepareSources task: compileJava.dependsOn prepareSources processResources.dependsOn prepareSources

  4. Add the new src directory to srcDir

Amnon Shochot
  • 8,998
  • 4
  • 24
  • 30