How do I copy jars from dependencies into a folder using Gradle?

35 Views Asked by At

I was trying to set up a docker container that required some jars to be added to Kafka. (Kafka with strimzi oauth). These jars are available on Maven and can therefore be added to my project as dependencies in Gradle.

How do I copy these Jars from maven into a folder so that the docker compose file can refer to them?

1

There are 1 best solutions below

0
Osama Javed On

Add this to gradle:

configurations {
    strimziJars
}
task copyStrimziJars(type: Copy) {
    from(configurations.strimziJars)
    into 'build/strimzi'
}
dependencies {
    strimziJars 'io.strimzi:kafka-oauth-client:Version', {
        transitive(false) // Dont want to bring anything else.
    }
    
}
tasks.integrationTest.dependsOn copyStrimziJars

This will create a folder called strimzi under the build directory tha can then be refered in my docker setup like:

    volumes:
      - ./build/strimzi:/opt/kafka/libs/strimzi  # downloaded from build.gradle and should be available in build/strimzi directory