I'm trying to make a Gradle plugin that will list all dependencies used to build the project. For simple compile and buildscript dependencies, that's fairly easy:
val dependencies = project.allprojects.asSequence().flatMap { project ->
(project.buildscript.configurations + project.configurations).asSequence()
.filter { it.isCanBeResolved }
.flatMap {
val resolved = it.resolvedConfiguration
resolved.rethrowFailure()
resolved.firstLevelModuleDependencies.flatMap { dep -> dep.allModuleArtifacts }
}
}
(then use it.id.componentIdentifier as ModuleComponentIdentifier to get to group, module and version, and it.type and it.classifier for those properties)
However, this misses jars used only by plugins. For example, when I apply the Kotlin plugin:
plugins {
kotlin("jvm") version "1.6.10"
}
the list will not include everything. Specifically, it'll include org.jetbrains.kotlin:kotlin-gradle-plugin and some siblings, but it doesn't include the pom dependency on org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin which is needed as well.
Can I get those dependencies out of the Gradle model as well?