Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 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!

like image 583
rodion Avatar asked Jul 30 '11 08:07

rodion


1 Answers

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
}
like image 74
Rene Groeschke Avatar answered Oct 15 '22 15:10

Rene Groeschke