Jar not working via a closure


(Matt Stromske) #1

Hello,

I am trying to create a jar through a closure. The reason for doing this is so other parts of the project can call this closure. The task appears to run with success, but no jar is created. What am I missing?

ext.blah = {
    jar {
        println "building blah jar"
        archiveName 'blah.jar'
        from('build/classes/main')
        destinationDir = file('build')
      }
}
  task doBlah
 {
    blah()
}

(Szczepan Faber) #2

Run with -i to find out more about the task. Perhaps it’s marked up-to-date, etc. How do you know if the task has actually ran? The debug statement “building blah jar” is printed always, regardless if the jar is built. It’s because the println method is invoked during Gradle’s configuration time. If you want to have this printed in the task execution time, you have to place it under doFirst {}.

In general, there are a couple of flaws in the code:

  • println debug statment is always printed (during configuration phase) instead of being printed when the jar is built

  • task ‘doBlah’ does completely nothing… the blah closure configures existing jar task (I assume that you apply the java plugin)

Can you tell us more what you’re trying to achieve?

Cheers!