Johannes Ernst
Johannes Ernst

Reputation: 3196

Gradle: run a task if at least one of its subprojects' tasks was executed

I'd like to create an archive (think: tar file) if at least one of the JARs built in my project have been updated, and skip building the archive if not. How do I do this in gradle?

More detail. Here's the project structure:

Top
   A1
      A11
      A12
   A2
      A21
   A3
      A31
      A32
      A33

Project Top is the top of the gradle hierarchy. Axx are projects that build a JAR each. I would like to run a task on level of A1 if either A11 or A12 (or both) have produced a new jar during the execution of the overall build, but skip it if neither has. Same for archives for A2 and A3.

The trigger would be "task has executed and succeeded" as opposed to "task has been skipped" or "task has been executed but failed".

Any ideas how to go about this?

Upvotes: 0

Views: 58

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14510

Gradle should handle this transparently for you with its up-to-date checking. If you properly declare that the task in A1 depends on the output of the JAR tasks in A11 and A12.

In order to do that, you should not configure A1 with paths pointing at build/... content but instead indicate that you want to use the output of tasks.

See the documentation for indications how this can be done.

Upvotes: 1

Related Questions