How to override "jar" task retaining default values for its properties?

Hello,

I’d like to override behavior of gradle’s “jar” task such that it puts the generated .jar file into a different directory.

The reason why I want to override the “jar” task rather than explicitly call it with the destinationDir property value is so that the .jar file is automatically delivered to the right directory when the “jar” task gets called as part of other gradle build project dependencies.

So, I tried something like this:

task jar(overwrite: true, type: Jar, dependsOn: classes) << {

println “Runing custom Jar”

destinationDir = new File(“myLib”) }

When I execute such overwritten “jar” task, here are two things I’m noticing

  1. .jar file still gets generated in its default location, and it only contains the MANIFEST file with no source compiled classes 2. nothing gets put into “myLib” directory I referenced above

Thanks.

So, to clarify, my question is why:

  1. No source compiled classes are included in my .jar file? 2. Why the jar is not placed into “myLib” directory I specified with the destinationDir property?

Thanks.