The Groovy Gradle Plugin
The Groovy Gradle Plugin (plugin id: groovy-gradle-plugin) lets you author Gradle plugins as precompiled Groovy DSL script plugins — .gradle scripts placed in a plugin source set such as buildSrc or an included build-logic build.
Each script is compiled into a binary Gradle plugin whose ID is derived from the script’s file name (and optional package).
For a step-by-step authoring guide — deriving plugin IDs, exposing extensions, and applying the resulting plugins — see Precompiled Script Plugins.
The Kotlin DSL equivalent is the kotlin-dsl plugin.
Usage
Apply the plugin in the build script of the project that hosts your script plugins (for example, buildSrc or build-logic):
plugins {
`groovy-gradle-plugin`
}
plugins {
id 'groovy-gradle-plugin'
}
Applying the plugin also applies the Groovy (base) plugin to compile the scripts and the Java Gradle Plugin Development plugin to expose them as plugins.
Gradle discovers every .gradle file in the plugin source set and registers it as a plugin in the gradlePlugin {} extension automatically.
A script named code-quality.gradle becomes the code-quality plugin, and a package declaration adds a prefix (for example, my.code-quality).
See the plugin ID section for details.
Project layout
src/main/groovy-
Precompiled Groovy DSL script plugins (
.gradlefiles). This is the Groovy source directory of the plugin source set configured on thegradlePlugin {}extension (themainsource set by default).
Tasks
The plugin adds the following tasks, which are wired into the compilation and output of the plugin source set. You do not normally run them directly; they participate automatically when the source set is built.
extractPluginRequests(typeExtractPluginRequestsTask)-
Extracts the
plugins {}block from each script plugin so that the plugins it requests can be applied. generatePluginAdapters(typeGeneratePluginAdaptersTask)-
Generates the Java adapter classes that expose each script as a binary Plugin implementation. The generated sources are added to the plugin source set’s Java sources.
compileGroovyPlugins(typeCompileGroovyScriptPluginsTask)-
Compiles the Groovy script plugins into plugin classes and adds them to the plugin source set’s output.
Notes
-
A precompiled script plugin ID must not start with
org.gradleand must not conflict with a core Gradle plugin. -
The file-name suffix determines how a script is interpreted:
.gradlebecomes aPlugin<Project>,.settings.gradleaPlugin<Settings>, and*.init.gradleaPlugin<Gradle>.