开发者

How to create a distribution archive (zip) containing project jars and war in Gradle

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 开发者_JS百科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!


here is a complete example to depend your Zip on the jar and the war task:

task dist(type:Zip){
    from jar.outputs.files
    from war.outputs.files
}


You can do the following to get all created archives of a build into your dist zip:

task dist(type:Zip){
    tasks.withType(AbstractArchiveTask).each{ archiveTask ->
        if(archiveTask!=dist){
            from archiveTask.outputs.files
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜