Search code examples
gradledependency-management

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.


Solution

  • 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'
    }