djangofan
djangofan

Reputation: 29689

How to get the file path location of a .jar dependency?

Lets say I have this dependency defined in my build.gradle:

dependencies {
    classpath "org.codehaus.groovy:groovy-all:2.4.0"
    classpath "com.opencsv:opencsv:3.1"
}

Is there a way for me to get the absolute file path location of the 2 .jar files resulting from the above dependency, as a List object?

Upvotes: 8

Views: 10847

Answers (3)

djangofan
djangofan

Reputation: 29689

This is how I did it, more explicitly:

project.buildscript.configurations.classpath.each {
    String jarName = it.getName();
    print jarName + ":"
}

Here is my build script URL.

Upvotes: 2

Opal
Opal

Reputation: 84864

The following piece of code will do the job:

apply plugin: 'java'

repositories {
   mavenCentral()
}

configurations {
   lol
}

dependencies {
    lol "org.codehaus.groovy:groovy-all:2.4.0"
    lol "com.opencsv:opencsv:3.1"
}

task printLocations << {
   configurations.lol.files.each { println it }
}

Don't know what's your goal but in general that's the way to go.

Upvotes: 20

Bhisham Balani
Bhisham Balani

Reputation: 228

Yes you can get physical path location from Configurations object. Reference: http://discuss.gradle.org/t/what-is-the-best-way-to-resolve-the-physical-location-of-a-declared-dependency/6999

Upvotes: 4

Related Questions