Reputation: 3680
I have a Gradle Task
to pull the dependencies from a project and play with that data. Below is my Gradle Task
task gavValidation() {
doLast {
project(':app').configurations.each {
configurationType ->
println "configurationType >>> "+configurationType.name
configurationType.allDependencies.each {
gav ->
println gav.group+" : "+gav.name+" : "+gav.version
}
}
}
}
The print
statement always come as null
when it is printing gav.version
above.
What i found is that, the versions of these dependencies are maintained in Spring Dependency Management
Plugin. Below is the snippet
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.RELEASE'
mavenBom 'io.pivotal.spring.cloud:spring-cloud-services-dependencies:1.5.0.RELEASE'
mavenBom 'org.springframework.boot:spring-boot-dependencies:1.5.13.RELEASE'
}
dependencies {
dependency 'io.springfox:springfox-swagger2:2.8.0'
dependency 'io.springfox:springfox-swagger-ui:2.8.0'
}
}
How to get the version in my custom-task ? that is currently coming as null
Upvotes: 0
Views: 199
Reputation: 12096
As explained in Working with Dependencies , the methods Configuration.getDependencies()
or Configuration.getAllDependencies()
only return the declared dependencies and do not trigger dependency resolution. So for dependencies coming from Spring BOM, the version is not known yet.
You can use Configuration.getResolvedConfiguration()
method instead, as follows:
task gavValidation() {
doLast {
configurations.each { configurationType ->
println " ***************** configurationType >>> " + configurationType.name
if (configurationType.canBeResolved) {
configurationType.getResolvedConfiguration().getResolvedArtifacts().each { artefact ->
ModuleVersionIdentifier id = artefact.getModuleVersion().getId()
println id.group + " : " + id.name + " : " + id.version
}
}
}
}
}
Upvotes: 1