Gradle: 'clone' original jar task to create a new task for a jar including dependencies -


i create new task in project creates jar archive class files of project , class files of dependencies (also called 'shaded jar' or 'fat jar').

the solution proposed gradle cookbook modifies standard jar task of javaplugin:

jar {     { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } } } 

however, keep original jar taks , have additional task shaeded jar, i.e. task behaves jar task, includes additional files according to

from { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } } 

and has classifier ('shaded').

i tried take on configuration of jar task copying properties this:

task shadedjar(type: jar, dependson: configurations.compile) {     dependencies = tasks.jar.taskdependencies     source = tasks.jar.source     manifest = tasks.jar.manifest     includes = tasks.jar.includes     classifier = 'shaded'      { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } } } 

but resulting tasks not take on dependencies of 'jar' , resulting jar not include project's class files. additionally, approach seems cumbersome recommended way of using existing task template new one.

what recommendable approach specific need (the seperate shadedjar task) , 'cloning' tasks use them templates additional tasks in general?

(i still on gradle 1.3,but solutions current gradle version welcome)

there no built-in way clone tasks. however, it's easy configure fatjar task include same files java plugin's jar task:

task fatjar(type: jar) {     appendix = "fat"     sourcesets.main.output // that's     { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } } } 

task autowiring automatically establish necessary task dependencies.

if build script goes on customize jar task, can apply customizations both tasks simultaneously:

configure([jar, fatjar]) {     version = "2.0"     entrycompression = "stored" } 

if, unlike in jar task's case, defining "template" yourself, can "instantiate" factory method:

def getmeanotherone(string name) {     task(name, type: jar) {        version = "2.0"        entrycompression = "stored"     } }  getmeanotherone("jar1") getmeanotherone("jar2") 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -