java - gradle - copy file after its generation -



try build jar , after copy folder.

task createjar(type: jar) {     archivename = "gradlejarproject.jar"     manifest {         attributes 'implementation-title': 'gradle jar file example',               'implementation-version': version,             'main-class': 'me.test.test'     }     basename = project.name     { configurations.compile.collect { it.isdirectory() ? : ziptree(it) } }     jar  }  task copyjartobin {     copy {         'build/libs/gradlejarproject.jar'         "d:/tmp"     } }  task buildapp (dependson: [clean, createjar, copyjartobin]) 

but can't figure out 1 problem. copyjartobin task try copy old jar. if delete /build folder in project , run buildapp() task, task createjar() generate .jar file, copyjartobin() won't find .jar file.

could me?
thanks.

the culprit copyjartobin task. when doing

task copyjartobin {     copy {         'build/libs/gradlejarproject.jar'         "d:/tmp"     } } 

you copy jar during configuration time using copy method. (see gradle user guide @ https://docs.gradle.org/current/userguide/userguide_single.html#sec:build_phases understand build lifecycle) want run actual copy operation during execution phase (the execution of task).

one way solve move call of copy method dolast block:

task copyjartobin {     dolast {         copy {             'build/libs/gradlejarproject.jar'             "d:/tmp"         }      } } 

the problem approach won't benefit of gradles incremental build feature , copy file every single time execute task though file hasn't changed.

a better , more idionmatic way of writing copyjartobin task change task implementation use copy task type:

task copyjartobin(type: copy) {     'build/libs/gradlejarproject.jar'     "d:/tmp" }    

we can improve snippet taking advantage of gradle's autowiring feature. can declare output of 1 task input another. instead of writing `build/libs/gradlejarproject.jar' can do:

task copyjartobin(type: copy) {     createjar // shortcut createjar.outputs.files     "d:/tmp" }    

now don't need bother task ordering gradle know createjar task must executed before copyjartobin task can executed.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -