25

I want to print the last version of a dependency in gradle.

I added my dependency in this way :

compile 'test:test:+'

now I want to print the version of my dependency, because I want to know which version I'm using.

I'm using it in this way :

gradle dependencyInsight --configuration compile --dependency test:test

But my output is this :

+--- test:test:+ -> project : (*)

Is there anyway I can get the real version of my dependency and not the +?

azizbekian
  • 60,783
  • 13
  • 169
  • 249
Daniel Taub
  • 5,133
  • 7
  • 42
  • 72

6 Answers6

17

Within app module's build.gradle I've imported Square's Moshi library as follows:


    dependencies {
        compile 'com.squareup.moshi:moshi:+'
    }

Then I executed following command in terminal:


./gradlew app:dependencyInsight --configuration compile --dependency com.squareup.moshi:moshi

Here's the output that I've received:

enter image description here

azizbekian
  • 60,783
  • 13
  • 169
  • 249
7

All easy, open hierarchy of view Project and see External Librariesenter image description here

serg3z
  • 1,852
  • 12
  • 28
  • 2
    As mentioned by OP in the first sentence of the question: `I want to print the last version of a dependency **in gradle**`. – azizbekian Feb 12 '18 at 06:22
  • 1
    If you want to find the latest version of the library use [gradle please](http://gradleplease.appspot.com) – serg3z Feb 12 '18 at 10:12
6

If you want to check the overview for all your dependencies, you can check with this command -

Solution 1-

./gradlew app:dependencies

Or

Solution 2-

If you want to check for any specific dependency.you can use gradles' build-in 'dependencyInsight : -

gradle dependencyInsight --configuration compile --dependency compile 'test:test:+'

or

Solution 3-

You can check your project .idea folder

inside your project -> .idea/libraries

there also you can see the final version of dependencies used.

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
4

You can do the following:

  • Use the configuration that contains your jar file
  • Filter for the the jar file's name
  • Print the results

This will print the full path as well as the version. You can extract just the jar name if needed.

 task printPmdVersion << {
    FileTree pmdJar = zipTree(configurations.pmd.filter {
        dep -> dep.name.contains("pmd-core")
    }.singleFile)
    println pmdJar
}

Example of output:

ZIP '/home/user/java/gradle_user_home/caches/modules-2/files-2.1/net.sourceforge.pmd/pmd-core/5.4.1/28715c2f768b58759bb5b373365997c30ac35899/pmd-core-5.4.1.jar'

superbAfterSemperPhi
  • 1,292
  • 1
  • 14
  • 27
3

Once you have added your dependency as "compile 'test:test:+'" build the project.

Then within the "Project" folder structure hierarchy find that dependency within "External Libraries" at the bottommost of folder structure , it will along with its version there. Use that version with your dependency and re-sync/build project again.

Dhaval Patel
  • 300
  • 1
  • 11
2

It's not a best practice use the '+' sign to always use the latest library version because you could not be able to have a repeatable build if you need one.

I mean, if you have to checkout your previous version of your APK from your Source Control Management system (e.g. Git) that you know it works fine, if you compile today (new library version could have been release)... maybe your old friend APK that was working fine... now it doesn't work fine like your latest one.

That said I suggest you using a gradle plugin like that:

https://github.com/ben-manes/gradle-versions-plugin

You will install in your build.gradle at project level like that:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.github.ben-manes.versions'

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And you'll find a new gradle task named dependencyUpdate that if you lunch it it will report you all your library versions compared with the latest ones:

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest milestone version:
 - com.github.ben-manes:gradle-versions-plugin:0.17.0
 - junit:junit:4.12

The following dependencies have later milestone versions:
 - com.android.support:appcompat-v7 [26.1.0 -> 27.0.2]
 - com.android.support.constraint:constraint-layout [1.0.2 -> 1.1.0-beta5]
 - com.android.support.test.espresso:espresso-core [3.0.1 -> 3.0.2-alpha1]
 - com.android.tools.build:gradle [3.0.1 -> 3.2.0-alpha03]
 - org.jacoco:org.jacoco.agent [0.7.4.201502262128 -> 0.8.0]
 - org.jacoco:org.jacoco.ant [0.7.4.201502262128 -> 0.8.0]
 - com.android.support.test:runner [1.0.1 -> 1.0.2-alpha1]

enter image description here

shadowsheep
  • 14,048
  • 3
  • 67
  • 77