Gradle and Multi-Project Structure

Gradle and Multi-Project structure

Most of this is pretty normal to the http://www.gradle.org/docs/current/userguide/multi_project_builds.html page. However you are going to need to add

evaluationDependsOn(':project1')
evaluationDependsOn(':project2')

so that gradle will evaluate project1 and project2 before module. In all the projects that contain code you will need to have an empty build.gradle file. This will also allow you to customize a project if needed.

Example: https://github.com/ethankhall/AndroidComplexBuild

Add a build.gradle at the root of your projects. So you need 4 that have useful information in it.

/build.gradle
/settings.gradle
/project1/build.gradle
/project2/build.gradle
/module/build.gradle

in /build.gradle put

dependencies {
project(":module")
}

in /settings.gradle put

include ':module'
include ':project1', ':project1:A1', ':project1:B1', ':project1:Z1'
include ':project2', ':project2:A2', ':project2:B2', ':project2:Z2'

in /project1/build.gradle put

apply plugin: 'java'

subprojects {
apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6

repositories{
mavenCentral()
}

//Anything else you would need here that would be shared across all subprojects
}

/project2/build.gradle

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}

subprojects {
apply plugin: 'android-library'

android {
compileSdkVersion 17
buildToolsVersion "17.0"
}

sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6

repositories{
mavenCentral()
}

//Anything else you would need here that would be shared across all subprojects
}

in /module/build.gradle put

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}

evaluationDependsOn(':project1')
evaluationDependsOn(':project2')

apply plugin: 'android'

android {
compileSdkVersion 17
buildToolsVersion "17.0"
}

dependencies {
compile project(":project1:A1")
compile project(":project1:B1")
compile project(":project1:Z1")

compile project(":project2:A2")
compile project(":project2:B2")
compile project(":project2:Z2")
}

How to create a transitive hierarchical multi-project in Gradle?

With multi-module builds, a module can depend on another module. To let the second project depend on the first, edit second-tool/build.gradle as:

dependencies {
implementation project(':first-tool')
}

Also, the first module should probably be:

dependencies {
api 'org.master-toolbox:some.other.tool:1.0'
}

You can use a multi-module build to do what you describe; you can have inter-module dependencies, and modules can be configured from the top-level build by using either allprojects { ... } or subprojects{ ... }.

Composite builds are rarely used- if you are happy with a "monolitic" build, and don't need to split your code into different repos. etc., then go with a (plain) multi-module build.



Related Topics



Leave a reply



Submit