clankerguru/opsx/gradle-custom-plugins
Claude Code and agent skill by clankerguru/opsx
- community
Checking that the SKILL.md file is still in the repository.
Writing Gradle plugins — Plugin<Project>/Settings/Gradle, extensions, precompiled script plugins, build-logic, TestKit.
Install
npx vskill@latest install clankerguru/opsx/gradle-custom-pluginsSKILL.md
The same SKILL.md was published earlier as clankerguru/opsx/gradle-custom-plugins.
Writing Custom Gradle Plugins
Three flavours, in increasing power:
- Script plugin — a
.gradle.ktsfile applied viaapply(from = ...). Legacy. - Precompiled script plugin — a
.gradle.ktsinbuildSrc/src/main/kotlinorbuild-logic/<module>/src/main/kotlin. Compiled once, reused, type-safe accessors. - Binary plugin — a Kotlin/Java class implementing
Plugin<T>, built as a jar, published or shared via composite. The full feature set.
Source:
- https://docs.gradle.org/current/userguide/custom_plugins.html
- https://docs.gradle.org/current/userguide/implementing_gradle_plugins.html
- https://docs.gradle.org/current/userguide/testing_gradle_plugins.html
1. Where plugin code lives
| Location | When to use | |
|---|---|---|
buildSrc/ | Simple, single project, no reuse across repos | |
build-logic/ as an included build | Multi-module or shared conventions | |
| Standalone repo published as jar | Reuse across multiple projects |
buildSrc implicitly applies to the build — no includeBuild needed — but its classpath is shared with everything. A composite build-logic is cleaner: lazier, parallelisable, and swappable.
Inside build-logic/settings.gradle.kts:
Each module is a Gradle plugin project — see §3.
2. Plugin<T> interface
Three target types:
| Interface | apply(T) param | Applied from | Purpose | |
|---|---|---|---|---|
Plugin<Project> | Project | build.gradle.kts plugins { } | 99% of plugins | |
Plugin<Settings> | Settings | settings.gradle.kts plugins { } | Toolchains, dep management, repos | |
Plugin<Gradle> | Gradle | Init scripts | Global hooks; see /gradle-init-scripts |
3. Binary plugin structure
java-gradle-plugin auto-registers the plugin marker, wires a TestKit dependency, and validates annotations. kotlin-dsl makes Kotlin-DSL idioms work inside the plugin.
Notes:
- Plugin markers:
java-gradle-plugingenerates a no-op pom named<id>.gradle.pluginso downstream builds can resolve by ID. implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:<v>")is the plugin marker coordinate; depending on it pulls the real plugin jar.
4. Precompiled script plugins
A .gradle.kts under src/main/kotlin becomes a plugin whose ID matches the file name (with optional package).
Apply as id("example.kotlin-jvm"). The file name example.kotlin-jvm.gradle.kts compiles to a plugin whose ID is the file name minus .gradle.kts.
Package directories count: src/main/kotlin/example/foo.gradle.kts → ID example.foo.
Pros: type-safe accessors, concise. Cons: no direct access to Plugin<T> lifecycle — for that, use a binary plugin.
5. Extensions
Extensions are the plugin's public API. extensions.create registers a typed extension bean.
Rules:
- Declare the extension as an
abstract class— Gradle synthesises a subclass with injectedProperty/ListProperty/ConfigurableFileCollectionbacking. - Prefer
Property<T>over plain fields: supports lazy wiring, configuration cache, input declarations. - Set defaults with
convention(...), not assignment — a user'sset(...)overrides a convention, so the plugin never clobbers user intent.
Using it:
Nested DSL blocks
Or a container for flavour-style configs:
6. Registering tasks from a plugin
Hooks onto other plugins:
withType/withPlugin are reactive: if the JavaPlugin is applied later, the block still runs.
7. Settings plugins
Registration in gradlePlugin { plugins { register("settings") { id = "..."; implementationClass = "..." } } } works the same as project plugins; it's the Plugin<Settings> interface that routes it.
8. Testing plugins
Unit test with ProjectBuilder
Fastest, no daemon, but no real execution.
Use for: task registration, extension wiring, exception on misuse.
Functional test with TestKit
Runs a real Gradle build in an isolated test directory.
withPluginClasspath() requires the java-gradle-plugin plugin in the plugin project — it injects the plugin under test.
Matrix-test against supported Gradle versions by parameterising .withGradleVersion(...).
9. Validation
Fails on:
- Missing
@Input/@Outputon task properties @Inputon aFiletype- Missing
@PathSensitiveon a cacheable input - Setter on a
Property<T>(should be abstract val)
Add tasks.validatePlugins { enableStricterValidation = true } to promote warnings to errors.
10. Publishing a plugin
./gradlew publishPlugins uploads to the Gradle Plugin Portal (needs credentials in ~/.gradle/gradle.properties).
11. Anti-patterns
Plugin<Project>with business logic directly inapply— split into task classes + extension.applyshould wire, not do.- Mutable
varfields in extensions — prevents lazy wiring. Use abstractProperty<T>. project.afterEvaluate { ... }— a smell. UsuallypluginManager.withPlugin(...)ortasks.withType(...).configureEach { }is cleaner and lazy.- Accessing another plugin's extension eagerly —
extensions.getByType(...)forces creation. Useextensions.configure<FooExt> { }or the reactive API. - A plugin that applies other plugins by string in an unguarded way —
plugins.apply("java-library")is fine, but if the caller already appliedjava, know that plugins are idempotent, and that ordering matters only viawithPlugin. - Publishing a plugin without
gradlePlugin { website/vcsUrl/tags }— rejected by the portal. - Using
Projectinside adoLastof a task your plugin registers — breaks configuration cache. Pass providers in.
12. Quick checklist for a new plugin
- [ ] Decide precompiled-script vs binary plugin.
- [ ] Extension with abstract
Propertyfields,conventiondefaults. - [ ] Tasks registered with
tasks.register<T>(...)(lazy), wired from extension via providers. - [ ]
pluginManager.withPlugin(...)for cross-plugin integration. - [ ]
@PathSensitive(RELATIVE)on file inputs;@CacheableTaskwhere deterministic. - [ ] Plugin marker via
java-gradle-plugin+gradlePlugin { plugins { register(...) } }. - [ ] Tests:
ProjectBuilderfor wiring,GradleRunnerfor behaviour. - [ ]
./gradlew validatePluginsclean.
13. Sub-skill cross-reference
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingcli/src/main/resources/content/skills/gradle-custom-plugins/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/clankerguru/opsx/gradle-custom-plugins)