I’m trying to build an uberjar based on the cookbook solution…that is working fine for classes and dependent jars. However, I can’t seem to get my resources (xml, etc.) included. Here’s the task defn:
If I do this…all of the classes and resources from the project make it. However, as soon as I uncomment the line dealing with the compileNoGemFire configuration, the project classes remain, but the resources do not. Strange.
the reason for that is that from { … } means that the closure is evaluated before passing it to the from closure. In a closure the last statement is interpreted as return value. That’s why you need at two seperate from blocks
It seems, that your resources are not part of the compileNoGemFire configuration but the classes are part of it.
A workaround might be putting just the from block with the configuration in a closure to defere the evaluation:
task uberJar(type: Jar) {
baseName = "foo-cacheserver-uberjar"
from sourceSets.main.output
from { configurations.compileNoGemFire.collect { it.isDirectory() ? it : zipTree(it) } }
}
...
from sourceSets.main.output
from { configurations.compileNoGemFire.collect { it.isDirectory() ? it : zipTree(it) } }
‘collect’ realizes the configuration (thereby resolving it). To defer this until execution time, you need to wrap the expression in a closure.‘from { foo; bar; baz }’ (as in your original post) won’t work because ‘foo’ and ‘bar’ don’t contribute to the value returned from the closure. Apart from potential side effects, they are no-ops.
Ahhhh…my slightly rusty Groovy-fu has gotten me into trouble. Totally forgot that only that last line of the closure is actually returned. (Had I been looking at a Clojure form, I would have totally spotted this!)
I suppose if I had somehow “accumulated” a collection of files and then returned that, it would have worked, no?
At any rate, your solution works perfectly guys. Thanks.