IppX
IppX

Reputation: 325

Gradle multiproject, multiple root projects and dependencies

Is it possible to reference (include) another gradle root project and its subprojects from my main root project?

Example: I currently have 2 gradle android multiprojects like this:

    rootA
        |--- android_lib_A1
        |--- android_lib_A2
        |--- androidapp_A

    rootB
        |--- android_lib_B1
        |--- android_lib_B2
        |--- androidapp_B

How can I properly include gradle project android_lib_B1 into rootA to use it in androidapp_A ?

The issues I currently face are the following:

I can make it work by publishing android_lib_B1 into my local maven repository, but I'd like to be able to compile it all together, without the extra publishing task.

I have seen that gradle's ProjectDescriptor has parent and children attributes, is this the way to go ?

Upvotes: 2

Views: 2513

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364858

You can link an external module in your project using

1) In your project rootA/settings.gradle

include ':android_lib_A1',':android_lib_A2',':androidapp_A' ':android_lib_B1'
project(':android_lib_B1').projectDir = new File("/path-to-project/rootB/android_lib_B1")

2) Add dependency in build.gradle of androidapp_A module

dependencies {
    compile project(':android_lib_B1')
}

Pay attention.
In this way you will be able to read the build.gradle in the android_lib_B1 but not the script in rootB. It means that if you have some tasks or functions defined in the rootB you have to add in the rootA or inside the android_lib_B1/build.gradle file.
Of course the rootB/settings.gradle will not be read since you are using the rootA project.

A partial solution could be to use a common folder where you can put your gradle files. You can link these files using:

apply from: 'gradleFolderScript/myFile.gradle'

Upvotes: 3

lance-java
lance-java

Reputation: 28071

Another option is to keep the projects separate and publish the artifacts to a common repository (eg artifactory). See publishing artifacts

Upvotes: 0

Related Questions