在Gradle中定义没有依赖关系的任务顺序? [英] Define task order without dependency in Gradle?

查看:243
本文介绍了在Gradle中定义没有依赖关系的任务顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我可以以某种方式确保任务将在另一个任务之前/之后执行,当两个任务都要执行时?我不希望在它们之间添加依赖关系。



背景



我有两个任务,一个启动服务器,另一个运行测试。启动该服务器的任务在新进程中运行它,因此我可以运行 gradle startServer runServerTests 。由于启动服务器需要一些时间,因此必须可以使用一个gradle进程启动服务器,然后使用另一个gradle进程多次运行测试。



现在我试图创建一个完成CI环境所做的任务,其中包括启动服务器和运行服务器测试。我显然希望在运行测试之前确保服务器已启动,但到目前为止,我运气不好。



尝试



我的第一次尝试是在下面,但是由于所定义的依赖关系的顺序,这不起作用不保证

 任务doItAll(dependsOn:[startServer,runServerTests]){...} 

我第二次尝试,调用任务 in actions 不起作用,并且

 任务doItAll()<< {
tasks.startServer.execute()
tasks.runServerTests.execute()
}

解决方案在路线图中( GRADLE-294 Initializer / Finalizer ),但现在没有帮助。

解决方案

目前这可能不会有太大帮助,但是我最近在这方面提交了一个拉取请求,并暗示它应该使它成为1.6(他们目前正在发布1.5版本,而PR没有将其发布到该版本中) - 请参阅讨论 here 。您最好的选择是等待1.5版发布后将拉取请求合并到主数据中,并然后从此处获取第一个可用的每晚构建。

编辑

Gradle 1.6已经发布了一段时间,现在你可以只需使用 mustRunAfter 来实现。有关详细信息,请参阅 Gradle手册中有关任务排序的部分


Question

Can I somehow make sure that a task will be executed before/after another task, when both of them are to be executed? I don't want to add a dependency between them that's always there.

Background

I have two tasks, one that starts a server and one that runs tests against it. The task that starts that server runs it in a new process, so I can run gradle startServer runServerTests. Since it takes some time to start the server, it must be possible to start a server with one gradle process and then run the tests several times with another gradle process.

Now I'm trying to create a single task that does all that our CI environment does, which includes starting a server and running the server tests. I obviously want to make sure that the server is started before running the tests, but so far I'm out of luck.

Attempts

My first attempt is below, but that does not work since the order of the defined dependencies is not guaranteed:

task doItAll(dependsOn: [startServer, runServerTests]) { ... }

My second attempt, calling the tasks in actions does not work and is not supported:

task doItAll() << {
  tasks.startServer.execute()
  tasks.runServerTests.execute()
}

Solutions are on the roadmap (GRADLE-294, Initializer/Finalizer), but that doesn't help me now.

解决方案

It probably won't help you much at the moment, but but I have submitted a pull request in this area recently and it was hinted that it should make it into 1.6 (they are currently releasing 1.5 and the PR didn't make it into that release) - see the discussion here . Your best bet is to wait for the pull request to be merged into master after 1.5 release and then grab the first available nightly build from here.

EDIT

Gradle 1.6 has been released some time ago and now you can simply use mustRunAfter to achieve that. See the section on task ordering in Gradle manual for details.

这篇关于在Gradle中定义没有依赖关系的任务顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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