Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gradle

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?

like image 368
djangofan Avatar asked Apr 08 '15 01:04

djangofan


3 Answers

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.

like image 148
Opal Avatar answered Oct 21 '22 15:10

Opal


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

like image 31
Bhisham Balani Avatar answered Oct 21 '22 17:10

Bhisham Balani


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.

like image 2
djangofan Avatar answered Oct 21 '22 17:10

djangofan