build 之前执行task_调用gradle“build”另一个项目中的任务

在使用Gradle初期,如何在当前项目的任务执行后调用另一个项目中的build任务?通过在settings.gradle中包含多个项目,然后在build.gradle中设置依赖关系,可以实现这一目标。例如,可以从项目myproject2的task中调用myproject1的build任务,前提是应用了java插件使build任务可用。
摘要由CSDN通过智能技术生成

I am only a couple of days into using gradle

In my current build.gradle script I have a task which I would like to call the build task in another project (ie. defined in a different build.gradle somewhere else) after each time it is executed

My question is how do I call a task from another project?

I guess I want to do something like tasks.build.execute() but it doesn't seem to work. I tried this:

commandLine "${rootDir}\\gradle", 'build', 'eclipse'

it at least executed the build and eclipse for my current project just not the master project. Hope my question is clear

解决方案

If you have a multi-project build

You need a root project that contains settings.gradle file with something like:

include 'myproject1'

include 'myproject2'

Than you can just make a dependency from one project to another like this:

myproject1/gradle.build

task someOtherTask() << {

println 'Hello'

}

myproject2/gradle.build

task sometask(dependsOn: ':myproject1:someOtherTask') << {

//do something here

}

Or if you want to call a task:

project(':myproject1').tasks.build.execute()

Notice: You have to apply java plugin to make build task available.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值