St.Antario
St.Antario

Reputation: 27395

Understanding gradle multiproject building

I have the following project tree:

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

MP::buiild.gradle:

dependencies {
    compile project(':API')
}

root:build.gradle:

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

root::settings.gradle:

include 'API', 'MP'

The thing is if we delete one of these three files gradle build task will fail. So it's not clear to me how java plugin builds the project. I run gradle build for MP::build.gradle, the following output was produced:

: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. 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. In my case it's just to get API project jar-file.

So my question is what is the subsequnce of actions to compile that jar. What will happens when gradle came across the 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?

Upvotes: 1

Views: 554

Answers (2)

Saida Babu  Chanda
Saida Babu Chanda

Reputation: 73

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 .

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. 3)execution ::

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

Upvotes: 0

guillaumBrisard
guillaumBrisard

Reputation: 69

To have quick look of what is going on in a java multiproject: http://www.gradle.org/docs/current/userguide/tutorial_java_projects.html

"For the subsequence of actions to compile that jar." Look at the diagram 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"

Upvotes: 1

Related Questions