Since I don’t have enough experience with Kotlin n...
# gradle
j
Since I don’t have enough experience with Kotlin nor with Gradle. Could somebody point me out to some example of how to create fat-jar with kotlin dsl in gradle?
g
same way as with java, apply shadowJar plugin, use tasks that build fat jars, configure if you want http://imperceptiblethoughts.com/shadow/
m
You could also adapt the jar task itself:
Copy code
tasks.withType<Jar> {
    manifest {
        attributes["Main-Class"] = mainClassName
    }
    from(configurations.runtime
        .filterNot { it.path.endsWith(".pom") }
        .map {
            if (it.isDirectory) {
                it
            } else {
                zipTree(it)
            }
        }) {
        exclude("META-INF/*.SF")
        exclude("META-INF/*.DSA")
        exclude("META-INF/*.RSA")
        exclude("**/pom.xml")
    }
}
g
Yes, but I wouldn’t recommend to do this. I don’t see why not just use a plugin that provides proper support of that, supports up-to-date checks, has integration with
application
plugin and of course allows to build fat jar and standard jar (to speed up development)
m
Well, if you just need a runnable jar this is as easy as it gets and never failed me until now, but otherwise I agree with you 🙂
g
it’s not idiomatic (business code in config file) and breaks up-to-date checks, imo enough to do not use it
e
the ad-hoc jar task configuration above also does dependency resolution at configuration time which will seriously impact the build performance
g
Ohh, this is even worse than up to date check. Just curious how would be correct to implement it to avoid resolution on configuration time? Use lazy configuration access?
e
one simple way would be to pass a provider to that
from()
function
👍 1
from(provider { configurations.runtime.filterNot { .. }... })