Learn Groovy - Plugin & Extension Development
Series/Learn Groovy/Episode 18
Episode 18 of 23

Learn Groovy - Plugin & Extension Development

This episode covers plugin and extension development with Groovy: creating Gradle plugins and Groovy application plugins, packaging and publishing artifacts, reuse in the build ecosystem, and contributing to community plugins and reusable scripts.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

Once you're proficient at writing scripts and DSLs, the next step is packaging that knowledge into a plugin that many people can reuse. Plugins are how Groovy distributes extensions in a structured way.

Episode 18 covers creating Gradle plugins, extensions for Groovy applications, packaging and publishing, and contributing to community plugins and reusable scripts.

Creating a Gradle Plugin

Plugin Structure

Plugin project structure
build.gradle
settings.gradle
src/main/groovy/com/example/GreetingPlugin.groovy
src/main/resources/META-INF/gradle-plugins/com.example.greeting.properties

The properties file links the plugin name to the implementation class. This is the contract Gradle reads when the plugin is applied.

Plugin Implementation

Gradle plugin implementation
package com.example
 
import org.gradle.api.Plugin
import org.gradle.api.Project
 
class GreetingPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.tasks.register("hello") {
            doLast {
                println "Halo dari ${project.name}"
            }
        }
    }
}

class GreetingPlugin implements Plugin<Project> is the basic contract of every Gradle plugin. project.tasks.register("hello") creates a new task that appears when the plugin is applied — now other projects just apply this plugin to get the hello task.

The Properties File

Register the plugin name
implementation-class=com.example.GreetingPlugin

implementation-class=com.example.GreetingPlugin links the plugin name com.example.greeting to the implementation class. implementation-class=com.example.GreetingPlugin is the only content that properties file needs.

Groovy Application Plugins

The Extension API

Simple extension
class NotifikasiExtension {
    String kanal = "slack"
    int retry = 3
}

class NotifikasiExtension defines configuration options with default values. String kanal = "slack" provides an initial value so users who configure nothing still get sensible behavior.

Registering an Extension in a Project

Register an extension
project.extensions.create("notifikasi", NotifikasiExtension)
project.tasks.register("kirimNotifikasi") {
    doLast {
        def config = project.extensions.notifikasi
        println "Mengirim ke ${config.kanal} dengan retry ${config.retry}"
    }
}

project.extensions.create("notifikasi", NotifikasiExtension) registers an extension that users can access. project.extensions.notifikasi reads the configuration from within the task, so user-set options take effect immediately.

Packaging and Publishing

Creating an Artifact

Package the plugin
gradle jar

Publishing to Maven Local

Publishing configuration
plugins {
    id "java-gradle-plugin"
    id "maven-publish"
}
 
publishing {
    publications {
        pluginMaven(MavenPublication) {
            from components.java
        }
    }
}

plugins { id "java-gradle-plugin" } adds Gradle plugin support, and id "maven-publish" adds publishing. pluginMaven(MavenPublication) defines the publication, which is then executed with gradle publishToMavenLocal.

Reuse in the Build Ecosystem

Use the plugin in another project
plugins {
    id "com.example.greeting" version "1.0.0"
}

id "com.example.greeting" version "1.0.0" applies the plugin along with its version. id "com.example.greeting" version "1.0.0" is the same pattern as the well-known Gradle plugins you've been using.

Reusable Scripts

A Groovy Script Library

Reusable script
def sambut(String nama) {
    "Halo, ${nama}"
}

Save it as lib/sambutan.groovy, then use it from the main script:

Use another script
evaluate(new File("lib/sambutan.groovy"))
println sambut("Arman")

evaluate(new File("lib/sambutan.groovy")) executes another script and makes its methods available. evaluate(new File("lib/sambutan.groovy")) is a simple way to share code between scripts before upgrading to a proper library.

Contributing to the Community

How to Contribute

Many Groovy plugins and scripts are open-source. To contribute:

  • Read the repository's contribution guide and code of conduct.
  • Start with issues labeled good first issue.
  • Write tests for your plugins or scripts.
  • Document the API with clear examples.

Maintaining Quality

Public plugins require high standards:

  • Semantic versioning for every change.
  • Automated tests before release.
  • Documentation explaining installation and usage.
  • Active maintenance of issues and pull requests.

Closing

Episode 18 taught you how to package Groovy code into shareable assets: Gradle plugins, extension APIs, packaging and publishing, reusable scripts, and contributions to the open-source ecosystem.

The key takeaways:

  • Gradle plugins implement Plugin<Project>.
  • A properties file links the plugin name to the class.
  • The extension API gives users configuration options.
  • maven-publish distributes the plugin as an artifact.
  • Plugins are reused with a plugins { id ... version } block.
  • evaluate shares code between Groovy scripts.

In episode 19 next, we'll discuss operational readiness and runbooks — preparing runbooks for deployment and incident response, operational metrics, logging and runtime observability, as well as upgrade paths and compatibility checks for Groovy and JVM versions.

Learn Groovy - Plugin & Extension Development | Learn Groovy