Reputation: 1530
Is there any way to list available plugins in gradle? Like gradle tasks --all
for plugins? If not, how do I get plugins from gradle project model?
Upvotes: 32
Views: 20506
Reputation: 144
Based on the answer by Opal and comment by Alexey Osipov I wrote this.
It prints plugin classes (without the instance ID) grouped by their containing location (e.g. JAR file), with some colorful highlighting – see the code below.
Tested on Gradle 8.6.
/**
* Lists loaded plugins, grouped by their containing location (JAR file, etc.).
*/
tasks.register('listPlugins') {task ->
doLast {
def out = services.get(StyledTextOutputFactory).create(task.name)
project.plugins
.collect { it.getClass() }
.groupBy { it.location }
.each { location, pluginMainClasses ->
final var path = location.toString().replaceFirst('(.*/).*', '$1')
final var filename = location.toString().replaceFirst('.*/', '')
out
.text('\n')
.style(Style.Normal).text(path) // regular white
.style(Style.Header).text(filename) // bright white
.println()
pluginMainClasses.each { mainClass ->
final var outermostClass = mainClass.name.replaceFirst('\\$.*', '')
final var nestedClasses = mainClass.name.replaceFirst('[^$]*(\\$?)', '$1')
out
.text(' ')
.style(Style.Success).text(outermostClass) // green
.style(Style.Info).text(nestedClasses) // yellow
.println()
}
}
}
}
Upvotes: 0
Reputation: 203
The list of plugins can be found in the properties of root project, via gradle properties
.
We can parse this information from the command-line using PowerShell:
gradle properties |
Where-Object { $_ -match '(?<=^plugins: \[).*(?=\])'; } |
Out-Null;
$Matches.Values -split ", " |
ForEach-Object { ($_ -split "@")[0]; }
I ran this command on my Spring Boot project using Gradle 6.7 and Powershell 7.1.0 and got the following output:
org.gradle.api.plugins.HelpTasksPlugin
org.gradle.buildinit.plugins.BuildInitPlugin
org.gradle.buildinit.plugins.WrapperPlugin
org.springframework.boot.gradle.plugin.SpringBootPlugin
org.gradle.language.base.plugins.LifecycleBasePlugin
org.gradle.api.plugins.BasePlugin
org.gradle.api.plugins.JvmEcosystemPlugin
org.gradle.api.plugins.ReportingBasePlugin
org.gradle.api.plugins.JavaBasePlugin$Inject
org.gradle.api.plugins.JavaPlugin
org.gradle.api.plugins.JavaLibraryPlugin
org.gradle.api.distribution.plugins.DistributionPlugin
org.gradle.api.plugins.ApplicationPlugin
Upvotes: 4
Reputation: 5415
As a complement to the accepted answer, one could also do as recommended in this answer by Peter Niederwieser
task showClasspath {
doLast {
buildscript.configurations.classpath.each { println it.name }
}
}
Which will show JAR names of the classpath dependencies, as well as the version of the jar.
Upvotes: 12