How to specify gradle build execution order

2019-08-02 03:59发布

问题:

My project structure is :

--Root project
  -- child 1
  * build.gradle
  * settings.gradle
  -- child 2
  * build.gradle
  * settings.gradle
  -- child 3
  * build.gradle
  * settings.gradle

Child 1 is dependent on jar file of child 2. Following is my build.gradle

group = 'com.test.test'
description = """project1"""
dependencies{
compile project(':project2')
}

Settings.gradle

rootProject.name = 'project1'
include ":Project2"
project(":Project2").projectDir = file("../Project2")

Is there any possibility in gradle to mention that project 2 should be executed before project1 and i can access project 2's dependency using something like

compile group: 'com.test.test', name: 'project2', version:'1.0'

Note: I am using Maven plugin in my gradle file. So I hope the dependency of project 2 will be updated in .m2 folder and can be accessed by project 1

回答1:

Your settings.gradle file has to be in your Root folder. It will include your 3 child projects.

include ":child 1"
include ":child 2"
include ":child 3"

Remove all settings.gradle from all your child project. Your child projects are considered as being a "module" of your single root "project".

New project structure :

--Root project
* build.gradle
* settings.gradle
  -- child 1
  * build.gradle
  -- child 2
  * build.gradle
  -- child 3
  * build.gradle

Then in your child project, you can specify the dependencies as your are already doing

project child 1 :

dependencies{
    compile project(':child 2')
}

It will compile "child 2" first, and then "child 1"

Depending on how you are configuring maven plugin for your projects, you will be able to publish your artifacts with a pom.xml generated with your dependencies.



标签: gradle groovy