How to resolve a dynamic version to a static one


(Jochen Berger) #1

Hi,

how can I resolve a dependency’s dynamic version to a static version from within a task? For example, I’d like to be able to turn “commons-io:commons-io:2.+” to “2.4”.

Thanks in advance for any hints.


(Marian Stránecký) #2

Hi Jochen,

I don’t understand the context of “within a task”, but I think you can mitigate your problem by setting up a resolution strategy, e.g.:

allprojects {

configurations.all { configuration ->

resolutionStrategy {

eachDependency {

if (requested.name == ‘some-artifact-name’) {

useVersion ‘2.2’

}

}

}

}

}

For more information on ResolutionStrategy, see http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html


(Jochen Berger) #3

Thanks, that actually got me a step further.

dependencies {

def x = compile ‘backport-util-concurrent:backport-util-concurrent:3.+’

def resolved = configurations.compile.resolvedConfiguration.getFirstLevelModuleDependencies(Specs.convertClosureToSpec {it == x})

println resolved.find().moduleVersion

} However, I feel that I’m overcomplicating things.


(Jochen Berger) #4

And another question is coming up: How do I determine whether a version is dynamic in the first place?