Dany
Dany

Reputation: 1530

How to list available plugins in Gradle

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

Answers (4)

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

Gao
Gao

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

Erik Živković
Erik Živković

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

Opal
Opal

Reputation: 84784

There's no such task that lists all the plugins applied to project. However this method may be helpful.

project.plugins.each {
   println it
}

Upvotes: 47

Related Questions