调用gradle“build”另一个项目中的任务 [英] calling gradle "build" task in another project

查看:935
本文介绍了调用gradle“build”另一个项目中的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只用了几天的时间使用gradle



在我当前的build.gradle脚本中,我有一个任务,我想在另一个任务中调用构建任务项目(即在其他地方定义在不同的build.gradle中)在每次执行之后



我的问题是如何从另一个项目调用任务?



我想我想做一些类似于tasks.build.execute()的东西,但它似乎不起作用。我试过这个:

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

它至少执行了当前项目的build和eclipse,而不是主项目。希望我的问题很明确

解决方案

首先阅读:
http://gradle.org/docs/current/userguide/multi_project_builds.html



如果您有一个多项目构建
您需要一个包含settings.gradle文件的根项目,如下所示:

  include'myproject1'
include'myproject2'

从一个项目到另一个项目的依赖关系如下所示:

myproject1 / gradle.build

  task someOtherTask()<< {
println'Hello'
}

myproject2 / gradle.build $>

 任务sometask(dependsOn:':myproject1:someOtherTask')<< {
//在这里做点什么
}

或者如果你想打电话一个任务:

$ p $ project(':myproject1')。tasks.build.execute()

$ b

注意:您必须应用java插件才能使构建任务可用。


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

解决方案

First read this: http://gradle.org/docs/current/userguide/multi_project_builds.html

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.

这篇关于调用gradle“build”另一个项目中的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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