其中大部分对于http://www.gradle.org/docs/current/userguide/multi_project_builds.html页面来说是很正常的。但是,您将需要添加
evaluationDependsOn(':project1')
evaluationDependsOn(':project2')
这样 gradle 将在模块之前评估 project1 和 project2。在所有包含代码的项目中,您需要有一个空的 build.gradle 文件。如果需要,这也将允许您自定义项目。
示例: https ://github.com/ethankhall/AndroidComplexBuild
在项目的根目录下添加 build.gradle。所以你需要4个有有用信息的。
/build.gradle
/settings.gradle
/project1/build.gradle
/project2/build.gradle
/module/build.gradle
在 /build.gradle 放
dependencies {
project(":module")
}
在 /settings.gradle 放
include ':module'
include ':project1', ':project1:A1', ':project1:B1', ':project1:Z1'
include ':project2', ':project2:A2', ':project2:B2', ':project2:Z2'
在 /project1/build.gradle 放
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
}
在 /module/build.gradle 放
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")
}