Slackbot
04/26/2022, 8:32 AMVampire
04/26/2022, 9:05 AMdependencies task.Lars Ködderitzsch
04/26/2022, 9:41 AMdependencies task uses configuration.incoming.resolutionResult - using that I can get to the imported BOMs of my platform.
Potentially I could now recurse into them by using another detached configuration.
However, whats stopping me, is that I can't figure how to access the version constraints listed in a BOM itselfVampire
04/26/2022, 10:18 AMdependencies task.
If you look at the result, you see that it shows the full tree and shows all the constraints (the lines with (c) in the end).
And I don't think the task makes several resolutions.Vampire
04/26/2022, 10:20 AMLars Ködderitzsch
04/26/2022, 11:07 AMdependencies tasks lists only constraints on the actual dependencies of a project.
However, I want to list all potential constraints of the platform the project is using.
For instance my platform is importing spring-boot-bom, cxf-bom and a few more, that's hundreds of potential dependencies which are version managed.
I'll have a look at version catalogs, although judging from https://docs.gradle.org/current/userguide/platforms.html#sub:platforms-vs-catalog a platform is what I really want.Vampire
04/26/2022, 12:13 PMVampire
04/26/2022, 12:20 PMLars Ködderitzsch
04/26/2022, 1:18 PM> gradlew findManaged --query=jakarta
Configuration on demand is an incubating feature.
> Task :findManagedDependency
--> Suche nach Dependency mit: jakarta
jakarta.inject:jakarta.inject-api:1.0.5 -> use: implementation("jakarta.inject:jakarta.inject-api")
jakarta.jws:jakarta.jws-api:2.1.0 -> use: implementation("jakarta.jws:jakarta.jws-api")
org.glassfish:jakarta.el:3.0.4 -> use: implementation("org.glassfish:jakarta.el")
...Lars Ködderitzsch
04/26/2022, 1:26 PMVampire
04/26/2022, 1:27 PMval checkForJdkActivatedProfiles by tasks.registering {
doLast {
val pomReader = MavenXpp3Reader()
fun collectAncestorPoms(pom: ResolvedArtifactResult, result: MutableList<ResolvedArtifactResult>) {
val parent = FileReader(pom.file)
.use { pomReader.read(it) }
.parent
if (parent != null) {
val parentPom = dependencies
.createArtifactResolutionQuery()
.forModule(parent.groupId, parent.artifactId, parent.version)
.withArtifacts(MavenModule::class.java, MavenPomArtifact::class.java)
.execute()
.resolvedComponents
.asSequence()
.flatMap { it.getArtifacts(MavenPomArtifact::class.java).asSequence() }
.filterIsInstance<ResolvedArtifactResult>()
.single()
result.add(parentPom)
collectAncestorPoms(parentPom, result)
}
}
dependencies
.createArtifactResolutionQuery()
.forComponents(configurations.filter { it.isCanBeResolved }.flatMap { configuration ->
configuration.incoming.resolutionResult.allDependencies.mapNotNull {
(it as? ResolvedDependencyResult)?.selected?.id
}
}.distinct())
.withArtifacts(MavenModule::class.java, MavenPomArtifact::class.java)
.execute()
.resolvedComponents
.asSequence()
.flatMap { it.getArtifacts(MavenPomArtifact::class.java).asSequence() }
.filterIsInstance<ResolvedArtifactResult>()
.map { pom ->
val ancestorPoms = mutableListOf<ResolvedArtifactResult>()
collectAncestorPoms(pom, ancestorPoms)
Pair(pom, ancestorPoms)
}
.forEach { (bottomPom, ancestorPoms) ->
sequenceOf(bottomPom, *ancestorPoms.toTypedArray()).forEach { pom ->
FileReader(pom.file)
.use { pomReader.read(it) }
.profiles
.forEach { profile ->
if ((profile.activation?.jdk != null) && (!profile.dependencies.isNullOrEmpty())) {
println("jdk activated Maven profile with dependencies found in ${pom.id}")
if (pom != bottomPom) {
println("ancestor of dependency ${bottomPom.id}")
}
}
}
}
}
}
}Vampire
04/26/2022, 1:29 PMregarding version catalogs, I'll look into them, though I am not quite sure how to maintain them for the 1500+ dependencies managed by the platform without going insane.Well, you can generate it from the information you just extracted. 🙂
Lars Ködderitzsch
04/26/2022, 1:30 PM