Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Gradle to build a jar with dependencies with Kotlin-DSL

There is already an answer to the question: how to include all the dependencies in a jar file though it's for Groovy

I'm using gradle with kotlin-dsl and the code is not compatible. I tried to make it work using a few ways including:

tasks.withType<Jar> {
    configurations["compileClasspath"].forEach { file: File ->
        copy {
            from(zipTree(file.absoluteFile))
        }
    }
}

Though this doesn't work. So how to include the dependencies using kotlin-dsl in gradle?

like image 517
guenhter Avatar asked Sep 11 '17 13:09

guenhter


1 Answers

This will work:

tasks.withType<Jar>() {
    configurations["compileClasspath"].forEach { file: File ->
        from(zipTree(file.absoluteFile))
    }
}

There's no need in copy { ... }, you should call from on the JAR task itself.

Note: Gradle does not allow changing the dependencies after they have been resolved. It means that the block above should be executed only after the dependencies { ... } are configured.

like image 167
hotkey Avatar answered Oct 11 '22 16:10

hotkey