Tobia
Tobia

Reputation: 18811

How can I use Gradle to just download JARs?

I have a non-standard project layout.

How can I use Gradle to just download a bunch of JAR dependencies into a lib directory, under the same directory where build.gradle is? For now, I don't need it to do anything else.

Here is what I have so far:

apply plugin: "java"

repositories {
    mavenCentral()
}

buildDir = "."
libsDirName = "lib"

dependencies {
    runtime group: "...", name: "...", version: "..."
}

If I run gradle build, it builds an empty JAR file in the lib directory, instead of downloading my dependencies there.

Switching "lib" with "." in the properties does not work either.

Upvotes: 18

Views: 16667

Answers (2)

Rohim Chou
Rohim Chou

Reputation: 1269

for downloading implementation, runtimeOnly dependencies, could use configurations.runtimeClasspath:

apply plugin: 'base'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.guava:guava:18.0'
    runtimeOnly 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
}

task copyDependencies(type: Copy) {
    from configurations.runtimeClasspath
    into 'lib'
}

then execute gradle copyDependencies

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691735

Something like the following should work:

apply plugin: 'base'

repositories {
    mavenCentral()
}

configurations {
    toCopy
}

dependencies {
    toCopy 'com.google.guava:guava:18.0'
    toCopy 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
}

task download(type: Copy) {
    from configurations.toCopy 
    into 'lib'
}

Upvotes: 34

Related Questions