gradle:未排序的dependsOn任务,如何处理?

发布于 2024-11-14 04:02:47 字数 676 浏览 2 评论 0原文

我的安装例程分为三个阶段:

1)下载 2)解压 3)配置

下载,使用ant.get和ant.checksum,所以我构建了自己的DownloadTask类,然后在构建中:

task download (type: DownloadTask) {
    url = url
    checksumAlgorithm = 'MD5'
    destFile = zipFile
}

所以我有4个任务:

task download {...}
task unzip {...}
task configure {..}
task install(dependsOn: [download, unzip, configure]) {}

但是我注意到dependsOn不尊重排序顺序,< a href="http://issues.gradle.org/browse/GRADLE-427" rel="nofollow">http://issues.gradle.org/browse/GRADLE-427

所以..这里的解决方法如何?

我不能仅将此任务作为方法移动,因为下载它使用我的 DownloadTask 类。我可以将所有内容移动为方法(甚至 DownloadTask),但这似乎不是最好的解决方案。

谢谢

I have three stages on my installation routine:

1) download
2) unzip
3) configure

downloads, use ant.get and ant.checksum, so I build my own DownloadTask class, and then in the build:

task download (type: DownloadTask) {
    url = url
    checksumAlgorithm = 'MD5'
    destFile = zipFile
}

so I came with 4 tasks:

task download {...}
task unzip {...}
task configure {..}
task install(dependsOn: [download, unzip, configure]) {}

But I get noticed that dependsOn don't respect the sort order, http://issues.gradle.org/browse/GRADLE-427

So.. how is the workaround here?

I cannot move only this tasks as methods, because download it uses my DownloadTask class. I can move all as methods (even DownloadTask), but don't seems the best solution here.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失眠症患者 2024-11-21 04:02:47

好吧,如果这对您有任何帮助,您也可以手动调用您的依赖项:

task install << {
    download.execute()
    unzip.execute()
    configure.execute()
}

我不认为这是真正的 Gradle 想法,但对于我的多项目构建来说,这效果很好。

问候,

Well, you also can call your dependencies by hand if this is any help for you:

task install << {
    download.execute()
    unzip.execute()
    configure.execute()
}

I do not think that this is the real Gradle idea, but for my multi-project build this worked quite well.

Greetings,

Jan

天涯离梦残月幽梦 2024-11-21 04:02:47

正如蒂姆提到的,您可以配置您的构建以具有这些依赖项。 “重用”任务是什么意思?您可以在此处使用自动装配,而不是使用 dependentOn 属性。

Autowire 意味着您将下载任务的输出声明为解压缩任务的输入,依此类推。在上面的示例中,url 将是下载任务的输入,destFile 是输出。这种方法可以轻松地重用每个任务,并且无需显式排序。在 gradle 用户指南的第 14.8 章中,您可以找到这种自动装配的简要介绍(http://www.gradle.org/current/docs/userguide/more_about_tasks.html#N10D4D)。也可以查看有关 TaskInputs 和 TaskOutputs 的 Javadoc(本章中提到)。

问候,
勒内

As tim mentioned you could configure your build to have these dependencies. What do you mean with "reusing" the tasks? You can use autowiring here instead of using the dependsOn property.

Autowire means, that you declare the output of task download as the input for the unzip task and so on. In your example above the url would be the input of your Download task and the destFile is the output. This approach makes it easy to reuse each task and makes explicit ordering unnecessary. In chapter 14.8 of the gradle userguide you can find a brief introduction to this kind of autowiring (http://www.gradle.org/current/docs/userguide/more_about_tasks.html#N10D4D). Have a look at the Javadoc about TaskInputs and TaskOutputs (mentioned in this chapter) too.

regards,
René

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文