Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly replace Gradle 'jar' task?

Tags:

gradle

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

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

I'm struggling to do this and I'm having a lot of trouble to achieve this. For example, I was unable to force the build task to always use my new task.

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

like image 576
ghik Avatar asked Mar 31 '12 11:03

ghik


1 Answers

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 { ... }
}
like image 131
Peter Niederwieser Avatar answered Nov 15 '22 09:11

Peter Niederwieser