如何在Gradle中配置多项目构建以在根项目中构建并单独构建它?

时间:2016-02-26 10:19:51

标签: java android gradle build

我在Gradle中配置多项目构建时遇到问题。

我的项目结构是:

├── Some-Java_project
│   ├── build.gradle
│   ├── one-java-suproject
│   │    └── build.gradle
│   └── second-android-subproject
│       └── build.gradle
├── settings.gradle
└── build.gradle

settings.gradle我有:

include ':Some-Java-Project'
include ':Some-Java-Project:one-java-subproject'
include ':Some-Java-Project:one-android-subprojects' 

和主gradle.build文件:

dependencies {
    compile project(path: ':Some-Java-Project:one-java-subproject', configuration: "android")
    compile project(path: ":Some-Java-Project:one-android-subprojects")

      ...
}

在 Some-Java-project我有依赖:

dependencies {
  ...
    //For Java EE
    compile project(path: ':Some-Java_project:one-java-suproject')

    //For android
    android project(path: ':Some-Java_project:one-java-suproject', configuration: 'android')
    android project(path: ':Some-Java_project:second-android-subproject')
...
}


subprojects.each { subproject -> evaluationDependsOn(subproject.path) }
jar.dependsOn subprojects.tasks["copyArtefacts"]
jar {
    baseName = 'someName'
    manifest {
        attributes 'Main-Class': 'some-name'
    }
    subprojects.each { subproject ->
        from fileTree(dir: 'build/classes')
    }
}

在每个gradle文件中:Some-Java-project 我有一个任务:

apply plugin: 'java'

...

//Copy build classes into project root build folder when assembling jar file
task copyArtefacts(type: Copy, dependsOn: 'compileJava') {
    from('build/classes/main/')
    into('../build/classes')
}

gradle.build:one-android-subprojects

apply plugin: 'com.android.library'
...

//Copy build classes into project root build folder when assembling jar file
task copyArtefacts(type: Copy, dependsOn: 'build') {
    from('build/intermediates/classes/release/')
    into('../build/classes')
}

...

这里的主要目标是将android和Java子项目构建为子项目 其他项目,获取编译的类并将它们放在一个jar文件中。 这个jar应该在root项目中使用。 现在配置正常,因为我直接引用子项目( one-java-suproject second-android-subproject )作为主根项目中Some-Java_project的叶子。但问题是,当我在其他位置结账Some-Java_project时,我不能简单地运行 等级构建,因为没有设置文件,Gradle找不到合适的项目,我希望有可能在根项目中构建项目,并且当源代码在其他地方作为独立库检出时。

如果我使用配置在Some-Java-prjoect下添加gradle设置:

settings.gradle

include ':one-java-subproject'
include ':one-android-subprojects' 

并更改它的工作依赖性,但我不想单独添加它。从存储库结账时,它应该可以立即使用。

0 个答案:

没有答案