How to execute assemble task twice?


(BR0WS3R) #1

I have a custom gradle plugin and a Task named ‘taskA’, and I want to achieve this task sequence: [assemble] -> taskA -> [assemble].

code:

taskA.dependsOn variant.assemble
taskA.finalizedBy variant.assemble 

Does gradle support to achieve this task sequence or can execute assemble twice in one build? If support, how to do?


(uklance) #2

Gradle will execute a task at most once per gradle invocation. I’m guessing you’re not doing the exact same thing twice (eg the task inputs are changed between the first and second invocation?)

It’s likely you’ll need two tasks, most likely of the same type but with different inputs/outputs.

I suggest you use separate input/output files/directories for each so that Gradle’s up to date check caching/skipping can still work.


(Shoaib Ali) #3

I have another question that pretty much boils down to the same issue of being able to invoke the compileJava task for each dynamic build task (one per brand). Create multiple shadowJars for each flavor of application

Is there any working sample/example that shows how to have multiple compile, assemble tasks?


(uklance) #4

I’ve written a java flavours plugin which has the following tasks for each flavour

  • compile<flavour>Java
  • compile<flavour>TestJava
  • <flavour>Classes
  • <flavour>Jar
  • <flavour>Test
  • <flavour>TestClasses
  • process<flavour>Resources
  • process<flavour>TestResources

Interesting code here