Created
July 4, 2025 11:03
-
-
Save bric3/9c290e43850ac0f87bf96bd12fec2188 to your computer and use it in GitHub Desktop.
Quick and dirty way to print added plugin to a project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Print the plugin id or its class when plugin is added to the project. | |
* | |
* Example usage: | |
* | |
* ```kotlin | |
* subprojects { | |
* logPluginWhenApplied(this) | |
* } | |
* ``` | |
* | |
* Also see https://github.com/gradle/gradle/issues/32463 | |
*/ | |
fun logPluginWhenApplied(project: Project) { | |
val pluginRegistry = project.serviceOf<org.gradle.api.internal.plugins.PluginRegistry>() | |
project.plugins.whenPluginAdded { | |
val publicType = (this@whenPluginAdded as? org.gradle.api.internal.GeneratedSubclass)?.publicType() | |
if (publicType == null) { | |
println("[${project.name}] applied plugin do not implement org.gradle.api.internal.GeneratedSubclass : $this@whenPluginAdded") | |
} else { | |
pluginRegistry.findPluginForClass(publicType) | |
.map { it.id } | |
.ifPresentOrElse( | |
{ println("[${project.name}] applied plugin id, $it") }, | |
{ println("[${project.name}] applied plugin has no id, $publicType") } | |
) | |
} | |
} | |
} | |
fun printClassHierarchy(clazz: Class<*>, indent: String = "") { | |
println("${indent}Class: ${clazz.name}") | |
clazz.interfaces.forEach { intf -> | |
println("${indent} Interface: ${intf.name}") | |
} | |
clazz.superclass?.let { superClass -> | |
printClassHierarchy(superClass, "$indent ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment