如何在 Gradle 中创建包含项目 jar 和 war 的分发存档 (zip)
我正在尝试创建一个 Zip 任务,该任务将为我的项目创建一个分发包,其中包含项目 jar 文件和 war(以及可能由 assemble 任务生成的其他构建工件)。
因此,我尝试编写这个简单的脚本
task dist(dependsOn: 'assemble', type: Zip){
into('lib'){
from 'build/libs' //contains jar and war files
}
... //other stuff
}
任务 dist
依赖于 assemble
因为它方便地包含创建 jar 和 war 文件的任务。
但如果我尝试执行该操作,gradle 会发出以下错误消息:
Circular dependency between tasks. Cycle includes [task ':assemble', task ':dist'].
我已经检查了 assemble
任务的规范,明确写着assemble
任务自动dependsOn
中的所有归档任务这项目,其中显然包括我的 dist
任务。而且似乎没有办法绕过它。
在 gradle 中执行此操作的正确方法是什么?如何制作依赖于 assemble 任务的 zip 任务?我可以使 dist
任务显式依赖于 jar
和 war
任务,但我认为这有点违反封装性。
我正在使用 gradle-1.0-milestone-3。
提前致谢!
I am trying to create a Zip task that would create a distribution package for my project that contains project jar files and war (and potentially other build artifacts produced by the assemble
task).
So I tried writing this simple script
task dist(dependsOn: 'assemble', type: Zip){
into('lib'){
from 'build/libs' //contains jar and war files
}
... //other stuff
}
Task dist
depends on assemble
because it conveniently includes the tasks that create jar and war files.
But if I try to execute that, gradle complains with this error message:
Circular dependency between tasks. Cycle includes [task ':assemble', task ':dist'].
I've checked out the specification for assemble
task, and it is clearly written that assemble
task automatically dependsOn
all archive tasks in the project, which obviously includes my dist
task. And there seems to be no way to get around it.
What would be the correct way of doing this in gradle? How can I make a zip task that depends on assemble
task? I could make dist
task explicitly depend on jar
and war
tasks, but I think that kind of violates encapsulation a bit.
I am using gradle-1.0-milestone-3.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个完整的示例,将您的 Zip 依赖于 jar 和 war 任务:
here is a complete example to depend your Zip on the jar and the war task:
您可以执行以下操作,将构建的所有创建的存档放入您的 dist zip 中:
You can do the following to get all created archives of a build into your dist zip: