Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 607
Tobia Avatar asked Sep 04 '15 16:09

Tobia


People also ask

Where does Gradle store downloaded jars?

The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.

Does Gradle build create jar?

The result JAR will be created in build/libs/ directory by default.

Where does Gradle fetch dependencies from?

Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module. To find out more about defining repositories, have a look at Declaring Repositories.


1 Answers

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'
}
like image 104
JB Nizet Avatar answered Sep 28 '22 09:09

JB Nizet