Gradle task or method to find resolved version of the dynamic dependency

(Mahesh Kelkar) #1

If I have a a dynamic dependency included as "org.apache.commons:commons-lang3:3+";

I am looking for gradle task or groovy method (i.e. programatic way) to find the actual version that it resolves to during build process e.g. 3+ resolved to 3.7

(Schalk Cronjé) #2

Firstly you can determine this from the command-line by doing something like

./gradlew dependencies --configuration=compile

(Substitute compile with the configuration of your choice).

To determine programmatically what it will be, you are required to resolve the configuration. So a simple way would be to do

project.configurations.getByName('WHATEVER').files.find { it.name.startsWith('commons-lang') }

or you could do

project.configurations.getByName('WHATEVER').resolvedConfiguration.resolvedArtifacts
    .find { name == 'commons-lang }.moduleVersion.id.version