如何指定gradle构建执行顺序 [英] How to specify gradle build execution order

查看:1346
本文介绍了如何指定gradle构建执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构是:

$ p $ - 根项目
- 子项1
*构建.gradle
* settings.gradle
- child 2
* build.gradle
* settings.gradle
- child 3
* build.gradle
* settings.gradle

子1依赖于子2的jar文件。我的build.gradle

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

Settings.gradle

  rootProject.name ='project1'
包含:Project2
项目(:Project2)。projectDir = file(../ Project2)

有没有在gradle中可能会提到项目2应该在project1之前执行,我可以使用像

 编译组来访问项目2的依赖项: 'com.test.test',名称:'project2',版本:'1.0'

注意:我在我的gradle文件中使用Maven插件。因此,我希望项目2的依赖项将在.m2文件夹中更新,并且可以通过项目1访问。 您的设置 gradle文件必须位于您的Root文件夹中。它包括您的3个子项目。

 包含:child 1
包含:child 2
包含:child 3

从您的所有子项目中删除所有settings.gradle。您的子项目被视为您的单根项目的模块。



新项目结构:

   - 根项目
* build.gradle
* settings.gradle
- 子项1
* build.gradle
- child 2
* build.gradle
- child 3
* build.gradle

然后在你的子项目中,你可以指定依赖关系,就像你已经在做的那样

项目子项1:

 依赖关系{
编译项目(':child 2')
}

它会首先编译孩子2,然后编译孩子1



您正在为您的项目配置maven插件,您将能够使用您的依赖关系生成的pom.xml发布工件。

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

解决方案

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构建执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆