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

I am trying to create a Zip task that will create a distribution for my project that contains the project jar and war files (and possibly other build artifacts created by the assemble task).

So, I tried to write this simple script

 task dist(dependsOn: 'assemble', type: Zip){ into('lib'){ from 'build/libs' //contains jar and war files } ... //other stuff } 

The dist task depends on assemble , because it includes tasks that create jar and war files.

But if I try to do this, gradle complains about this error message:

 Circular dependency between tasks. Cycle includes [task ':assemble', task ':dist']. 

I checked the specification for the assemble task , and it is clearly written that the assemble task automatically dependsOn all archive tasks in the project, which obviously includes my dist task. And there seems to be no way around this.

What would be the correct way to do this in gradle? How can I make a zip task that depends on assemble task? I could make the dist task explicitly dependent on the jar and war tasks, but I think this breaks the encapsulation a bit.

I am using gradle -1.0-milestone-3.

Thanks in advance!

+6
source share
2 answers

here is a complete example to depend on your zip on jar and military task:

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

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

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

Source: https://habr.com/ru/post/893931/


All Articles