简体   繁体   English

了解Gradle多项目构建

[英]Understanding gradle multiproject building

I have the following project tree: 我有以下项目树:

root
 |
 |--MP
 |  |
 |  |---build.gradle
 |
 |--API
 |
 |---build.gradle
 |
 |---settings.gradle

MP::buiild.gradle: MP :: buiild.gradle:

dependencies {
    compile project(':API')
}

root:build.gradle: 根:的build.gradle:

subprojects{
    apply plugin : 'java'
    repositories{
        mavenCentral()
    }
    version = '1.0'
    jar{
        manifest{
            attributes 'Gradle': 'Multiproject'
        }
    }
}

root::settings.gradle: 根:: settings.gradle:

include 'API', 'MP'

The thing is if we delete one of these three files gradle build task will fail. 问题是,如果我们删除这三个文件之一, gradle build任务将失败。 So it's not clear to me how java plugin builds the project. 因此,我不清楚java plugin如何构建项目。 I run gradle build for MP::build.gradle , the following output was produced: 我为MP::build.gradle运行gradle build ,产生了以下输出:

:API:compileJava
:API:processResources UP-TO-DATE
:API:classes
:API:jar
:MP:compileJava
:MP:processResources UP-TO-DATE
:MP:classes
:MP:jar
:MP:assemble
:MP:compileTestJava UP-TO-DATE
:MP:processTestResources UP-TO-DATE
:MP:testClasses UP-TO-DATE
:MP:test UP-TO-DATE
:MP:check UP-TO-DATE
:MP:build

So, the first what we need to do when we run gradle build for MP::build.gradle is to resolve all dependecies. 因此,当我们为MP::build.gradle运行gradle build时,我们gradle build MP::build.gradle是解决所有依赖关系。 As far as I understand it means to load jars from an external repositories and, if need, to compile jar -files from a separate projects. 据我了解,这意味着要从外部存储库加载jar,并在需要时从单独的项目编译jar文件。 In my case it's just to get API project jar -file. 就我而言,这只是获取API项目jar -file。

So my question is what is the subsequnce of actions to compile that jar . 所以我的问题是,编译该jar的动作的子序列是什么。 What will happens when gradle came across the compie project(':API') . gradle遇到compie project(':API')时会发生什么。 It's looking for the gradle.settings file and report an error if there isn't or it's looking for build.gradle in the root directory first? 它正在寻找gradle.settings文件并报告错误(如果没有),或者它build.gradle在根目录中寻找build.gradle

To have quick look of what is going on in a java multiproject: http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html 要快速了解Java多项目中发生的情况,请访问: http : //www.gradle.org/docs/current/userguide/tutorial_java_projects.html

"For the subsequence of actions to compile that jar." “对于编译该jar的动作的子序列。” Look at the diagram http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html 查看该图http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html

And for crossproject dependencies http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:cross_project_configuration Quote: "By default, the configuration of all projects happens before any task is executed" 对于跨项目的依赖关系, http ://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:cross_project_configuration Quote:“默认情况下,所有项目的配置都在执行任何任务之前进行”

I hope you have already figured it out . 我希望你已经知道了。

So the gradle build life cycle explains it ... the life cycle is as below 1) initialisation 2) configuation 3) execuion . 因此gradle构建生命周期对其进行了解释...生命周期如下1)初始化2)配置3)执行。

for your particular case of a multi project build , what happens is 对于您的多项目构建的特殊情况,会发生什么

1) initialisation :: here the settings.gradle is searched for no matter from which project you run it (it always tries to find settings.gradle file when you run a task and includes those projects defined in its include directive.) 2) configures it creates the task tree based on the task you have tried to run and its dependencies. 1)初始化::在这里,无论您从哪个项目运行都将搜索settings.gradle(运行任务时,它总是尝试查找settings.gradle文件,并包含其include指令中定义的那些项目。)2)配置它根据您尝试运行的任务及其依赖关系创建任务树。 3)execution :: 3)执行::

runs the task tree. 运行任务树。

Please let me know if this is helpful. 请告诉我这是否有帮助。

You can read this page for more clarity. 您可以阅读此页面以更清楚。

http://www.gradle.org/docs/current/userguide/build_lifecycle.html http://www.gradle.org/docs/current/userguide/build_lifecycle.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM