How to replace Gradle 'jar' task correctly?

I am trying to get Gradle to create a jar in my own way. I wrote my own Gradle task (separate class) to do this, and now I want to replace the default task with jarit so that:

  • the archive is ALWAYS generated with my new task and NEVER with the old task jar
  • my new task has the same relationship with other tasks as the default task jar- it depends on the task classes, the task builduses it, etc.
  • I would like my task not to be called when it is UP-TO-DATE(as by default jar)

I am struggling to do this, and I have many problems to achieve this. For example, I could not get the task to buildalways use my new task.

I would really appreciate it if someone could support me with a short howto.

+5
source share
1 answer

This should work:

jar {
    // reset actions
    actions = []
    // add your action that performs the work based
    // on the configuration (e.g. 'source') of this task
    doLast { ... }
}
+2
source

All Articles