Example gradle script to build(clean, build) several projects in the right order

There are several projects that need to build in order. By build in order the meaning:

  1. clean, build - project 2
  2. clean, build - project 1
  3. clean, build - project 4
  4. clean, build - project 3

of each project

-Root Folder
------- project1
-----------build.gradle
------- project2
-----------build.gradle
------- project3
-----------build.gradle
------- project4
-----------build.gradle
–build.gradle
–settings.gradle

root_folder/settings.gradle

include ‘:project1’, ‘:project2’, ‘:project3’, ‘:project4’

root_folder/build.gradle

???

Please tell me how to organize the build order of all the projects in a script?

Can you give a little bit more context to your projects and why they need to built in a particular order? Typically this is because certain projects depend on others, which should be expressed via project dependencies.

Yes of course. The fact that this is a big project, which consists of a few, and all projects are collected in the war-archive from git repository. And in the case of changes in the projects we need them all over again rebuild. So, for convenience, it was decided to make the build script projects.

project1

apply plugin: 'java’
apply plugin: 'eclipse’
apply plugin: 'maven-publish’
apply plugin: ‘eclipse-wtp’

repositories {
mavenCentral()
mavenLocal()
}

publishing {
repositories {
mavenLocal()
}
publications {
maven(MavenPublication) {
groupId 'path.project1’
artifactId 'project1’
version ‘1.0’

        from components.java
    }
}

}

project2

apply plugin: 'java’
apply plugin: 'eclipse’
apply plugin: ‘maven-publish’

task sourceJar(type: Jar) {
from sourceSets.main.allJava
}

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
    compile group: 'path', name: 'project1', version: '1.0'
    compile group: 'path.project1', name: 'subproject1', version: '1.0'
    compile group: 'path.project1', name: 'subproject2', version: '1.0'        
}
version = '1.0'
sourceCompatibility=1.7
targetCompatibility = 1.7

publishing {
repositories {
mavenLocal()
}

publications {
    maven(MavenPublication) {
        groupId 'path'
        artifactId 'project2'
        version '1.0'
        from components.java
        artifact sourceJar {
            classifier "sources"
        }
    }
}

}

etc. Thanks.

If I understand you right, you are building your projects, which then publish to a Maven repo and then the next project pulls that new artifact down from the repo, which is why they have to build in a particular order?

This is what project dependencies are for.

Thanks for your help.