我有一个Gradle Task
来从项目中提取依赖项并使用该数据。下面是我的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
}
}
}
}
当print
打印null
时,gav.version
声明总是来自Spring Dependency Management
。
我发现,这些依赖项的版本在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'
}
}
插件中维护。以下是片段
Working with Dependencies
如何在我的自定义任务中获取该版本?目前为空
正如在Configuration.getDependencies()
中所解释的那样,方法Configuration.getAllDependencies()
或Configuration.getResolvedConfiguration()
只返回声明的依赖项,并且不会触发依赖项解析。因此,对于来自Spring BOM的依赖项,该版本尚不为人所知。
您可以使用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
}
}
}
}
}
方法,如下所示:
qazxswpoi