Moving built-in tasks gradle works to complete tasks / built-in tasks shourtcuts

I want to create a simple synchronization task that will slightly change its behavior depending on the type of assembly (for example, debug / release), and I use the 'dummy' decrared boolean variable in gradle.taskGraph.whenReady:

gradle.taskGraph.whenReady {taskGraph -> dummy = false if (taskGraph.hasTask(':dummybuild')) { dummy = true } } 

The problem is that the task configured as follows has a configuration area, that is, before Ready, so it does not have access to the 'dummy' variable:

 task copySkins(type: Sync) { from skinsFrom into skinsInto rename skinsRename exclude symbianExclude if (!dummy) exclude dummyExclude } 

I am using this workaround now

 task copySkins { inputs.dir skinsFrom outputs.dir skinsInto doLast { task skins(type: Sync) { from skinsFrom into skinsInto rename skinsRename exclude symbianExclude if (!dummy) exclude dummyExclude } skins.execute() } } 

Is it possible

  • Detect / configure some properties of the assembly in any other place, except whenReady
  • move synchronization task task to doLast
  • or at least have a shortcut for the synchronization task (.execute () looks pretty ugly)
+4
source share
1 answer

1) whenReady event allows the user to access a fully initialized task schedule: initialization is completed and tasks are ready to run. The only situation where you need to discover / set the properties of an assembly here is when you need to examine the current configuration of the assembly. If you do not need this information, you can place your initialization anywhere in your script assembly. At the very end, this is nothing but a groovy script.

  apply plugin: 'java'
     def now = new Date ()
     compileJava.doFirst {
       println "It is $ {now}. We are starting to compile"
     }

2) You cannot move the synchronization task to doLast. But you can always add your actions to makeFirst;) I think this should work:

  task copySkins (type: Sync) {
   from skinsFrom
   into skinsInto
   rename skinsRename
   exclude symbianExclude

   doFirst {
     if (! dummy) exclude dummyExclude
   }
 }

3) With all the previously mentioned drawbacks of synchronization, synchronization tasks should not be painful

+2
source

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


All Articles