dependencies {
api "io.netty:netty-all"
api "com.google.protobuf:protobuf-java:3.22.2"
testImplementation "org.springframework:spring-tx:6.0.8"
testImplementation "org.springframework.boot:spring-boot-starter-test:${libs.versions.springBoot.get()}"
}
project.afterEvaluate {
project.configurations.forEach {
for (final def dependency in it.dependencies) {
println dependency.group + ":" + dependency.name + ":" + dependency.version
}
}
}
io.netty:netty-all:null
com.google.protobuf:protobuf-java:3.22.2
org.projectlombok:lombok:null
org.springframework.boot:spring-boot-configuration-processor:null
org.springframework.boot:spring-boot-autoconfigure-processor:null
com.livk.boot:spring-extension-dependencies:1.0.7
io.grpc:protoc-gen-grpc-java:1.53.0
com.google.protobuf:protoc:3.22.2
org.springframework:spring-tx:6.0.8
org.springframework.boot:spring-boot-starter-test:3.0.6
netty-all comes from the springboot version statement, but this way is unable to get the version, what should I do to get it
Vampire
(Björn Kautler)
May 12, 2023, 8:33am
2
You are checking the declared version and this correctly is null
as you didn’t declare a version.
You probably need to resolve the configuration and check the resolution result.
Because I used the platform to declare the version, the dependency can be imported correctly, but it cannot be taken out directly, it can only be obtained through incoming.resolutionResult.allDependencies
The following way can indeed solve the problem correctly
Is there a better way?
project.afterEvaluate {
def dependencyResultMap = new HashMap<String, String>()
List.of(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).forEach { configurationName ->
project.configurations.named(configurationName).get().incoming.resolutionResult.allDependencies {
def result = requested.displayName.split(":")
if (result.length == 3) {
dependencyResultMap.put(result[0] + ":" + result[1], result[2])
}
}
}
project.configurations.forEach { configuration ->
configuration.dependencies.forEach { dependency ->
def version = dependency.version
if (version == null || version.isBlank()) {
version = dependencyResultMap.get(dependency.group + ":" + dependency.name)
}
println dependency.group + ":" + dependency.name + ":" + version
}
}
}
io.netty:netty-all:4.1.90.Final
com.google.protobuf:protobuf-java:3.22.2
org.projectlombok:lombok:1.18.26
org.springframework.boot:spring-boot-configuration-processor:3.0.5
org.springframework.boot:spring-boot-autoconfigure-processor:3.0.5
com.livk.boot:spring-extension-dependencies:1.0.7
io.grpc:protoc-gen-grpc-java:1.53.0
com.google.protobuf:protoc:3.22.2
org.springframework:spring-tx:6.0.7
org.springframework.boot:spring-boot-starter-test:3.0.5
1 Like
This actually helped me to capture information that I was missing.
I too was referencing only the declared dependencies, and the reference to incoming.resolutionResult
was exactly the change I needed.
Thanks for this example!