kotlin-tooling-kotlin-toolchain-plugin-authoring
Load when authoring, writing, or designing a Kotlin Toolchain local plugin to extend the declarative build with code generation, build-time processing, custom verification, or packaging that module.yaml cannot express, or when referencing @TaskAction, @Configurable, plugin.yaml, or jvm/amper-plugin.
- 0
- Installs
- —
- Rating
- —
- Success rate
- 2
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 584bc544af353a89… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Kotlin Toolchain Plugin Authoring
Local plugins are the official escape hatch from declarative YAML: a jvm/amper-plugin module shipping
task actions, settings, and generated sources/resources alongside your project. Code patterns to adapt are
in references/examples.md.
When to write a plugin
Write one when you need:
- A build-time step a library's workflow expects (code generation, schema compilation, resource transformation, version stamping).
- Custom verification wired into the build (pre-release checks, schema validation, contract tests).
- A build-time value published into the JAR classpath or downstream tasks — the closest analog to Gradle's
project.version. - A named CLI command for a repeated workflow (
./kotlin do release).
Don't write one when module.yaml already covers it (dependencies, JDK provisioning, source layouts,
basic packaging), and never to reuse a Gradle plugin — the Kotlin Toolchain cannot consume them.
Layout
repo-root/
├── kotlin, kotlin.bat # wrappers (from `kotlin init`)
├── project.yaml # registers the plugin
├── plugins/<name>/
│ ├── module.yaml # product: jvm/amper-plugin
│ ├── plugin.yaml # tasks: + commands: + generated:
│ └── src/
│ ├── Settings.kt # @Configurable interface
│ ├── tasks/ # one @TaskAction per file
│ │ ├── Foo.kt
│ │ └── FooSteps.kt # internal shared helpers (not @TaskAction)
│ └── <domain logic>/
└── <consumer-module>/
└── module.yaml # plugins: { <name>: enabled: true, ... }
Keep at least one consumer module in the repo — it is the only way to exercise the plugin end-to-end, and plugins cannot be published to any public registry yet.
project.yaml
modules:
- consumer-app
- plugins/<name>
plugins:
- ./plugins/<name>
Without the top-level plugins: block the plugin id is unresolvable from any consumer.
module.yaml — the plugin module
product: jvm/amper-plugin # marks the module as a plugin
dependencies:
- <coordinate>:<version>
- <coordinate>:<version>: runtime-only # required only at runtime
- <coordinate>:<version>: compile-only
pluginInfo:
id: <plugin-id> # what consumers write under `plugins:`
settingsClass: <fully.qualified.Settings> # the @Configurable interface
settings:
jvm:
jdk:
version: 21
kotlin:
languageVersion: 2.1
@Configurable interface Settings
Defaults go in interface property getters; nested blocks become nested @Configurable interfaces.
@Configurable
interface Settings {
val someValue: String get() = "default"
val checks: ChecksSettings
}
@Configurable
interface ChecksSettings {
val strict: Boolean get() = true
}
Consumers override what they need in module.yaml; omitted values fall back to the getter default:
plugins:
<plugin-id>:
enabled: true
someValue: "override"
checks:
strict: false
@TaskAction
Task actions are top-level funs, called when the matching plugin.yaml entry executes.
@TaskAction
fun foo(
@Input moduleRootDir: Path,
@Output outputDir: Path,
settings: Settings,
) {
// body
}
@Input path: Path— declared input; Kotlin Toolchain snapshots its contents for execution avoidance.@Output path: Path— declared output directory; Kotlin Toolchain creates it and passes the path in. Write to the exactPathyou received, or downstream references won't find the result.settings: Settings(or any@Configurable) — typed configuration, wired inplugin.yaml.- Plain
Path/ primitives — passed literally fromplugin.yaml. println(...)is the output channel; Kotlin Toolchain captures stdout.
Execution avoidance
A @TaskAction is skipped when its declared inputs are unchanged. Tasks whose real inputs are Git history,
the network, or environment variables cannot be fingerprinted, so opt out:
@TaskAction(executionAvoidance = ExecutionAvoidance.Disabled)
fun foo(@Output outputDir: Path, settings: Settings) { /* ... */ }
Tasks with no @Output are never cached and always re-run — correct for purely side-effecting tasks
(releases, deployments, pushes).
plugin.yaml
tasks:
foo:
action: !<fully.qualified.foo>
moduleRootDir: ${module.rootDir}
outputDir: ${taskOutputDir}
settings: ${pluginSettings}
bar:
action: !<fully.qualified.bar>
input: ${tasks.foo.action.outputDir}/result.txt
settings: ${pluginSettings}
generated:
resources:
- directory: ${tasks.foo.action.outputDir}
commands:
- foo
| Reference | Resolves to |
|---|---|
${module.rootDir} | Directory containing the consumer's module.yaml. Pass as @Input to inspect the consumer's tree. |
${taskOutputDir} | Toolchain-managed per-task output directory. Pass as @Output. |
${pluginSettings} | The @Configurable object built from the consumer's module.yaml. |
${tasks.<task>.action.<param>} | Another task's parameter — used in generated.* and to wire one task's @Input to another's @Output. |
generated.resources / generated.sources
Both register a directory (usually a task's @Output) as a contribution to the consumer's build, and both
auto-wire the producing task to run first:
generated.resources— added to the JAR classpath, reachable viagetResourceAsStream("/path/in/jar").generated.sources— added as a Kotlin source root and compiled with the consumer'ssrc/.
Tasks vs commands
Tasks are the implementation, addressed as ./kotlin task :<module>:<task>@<plugin-id> — the docs advise
against relying on that mangled name. Commands are the public API: ./kotlin do <command-name>, listed via
./kotlin show commands (-m <module> to scope).
- A task whose
@Outputfeedsgenerated.resources/generated.sourcesis a build-graph contributor. Keep it out ofcommands:; it runs automatically and exposing it invites users to run it by hand. - A task users invoke directly must be in
commands:.
File-based task communication
There is no shared mutable build state — no project.version, no extension property maps. Tasks talk
through matched paths:
- The producer takes
@Output outputDir: Pathand writes files into it. plugin.yamlpoints a consumer task's@Inputat${tasks.<producer>.action.outputDir}/<file>.- The Toolchain infers the dependency from the path match — no
dependsOnAPI needed.
The same @Output directory can serve build-time consumers (via @Input) and runtime consumers
(registered under generated.resources, read via getResourceAsStream) simultaneously.
Runtime overrides via environment variables
There is no -Pkey=value. Read env vars inside the action for ephemeral overrides:
val forced = System.getenv("MYPLUGIN_FORCE_VALUE")?.takeIf { it.isNotBlank() }
val skipChecks = System.getenv("MYPLUGIN_SKIP_CHECKS")?.equals("true", ignoreCase = true) == true
Pass the env map in as a constructor parameter rather than calling System.getenv() deep in the call stack,
so logic stays unit-testable. Document every recognised variable in the plugin's README. Env vars are
ephemeral overrides, not a trust boundary — validate a value before using it in a file path or process
argument.
Sharing logic across task actions
Tasks often share steps (verify → create → push). Don't compose an atomic user-facing task from a chain of build-graph tasks: separate invocations re-open shared resources and open a window where another process observes intermediate state.
Limitations to design around
- Plugins are local-only; no public registry publishing yet.
- Plugins are module-level; there is no project-wide plugin. Every consumer module lists it under
plugins:, and cross-module effects flow through files. - No
${...}interpolation inmodule.yaml(as of 0.11) — consumer settings are literal values. - No
Project.afterEvaluate, no lazyProvider/Propertygraph. Compute derived values in the action body. -h/--helpdoes not list plugin commands; use./kotlin show commands.
Validate against a consumer
- Add a small consumer module (
demo-app/,sample/) enabling the plugin with realistic settings. - Have its
main.ktor a test read whatever the plugin publishes. - Put the exact commands and expected output in the plugin's README, so a fresh clone can paste and compare.
Plugin docs: https://kotlin-toolchain.org/dev/user-guide/plugins/
Files
2- SKILL.md
ff5cf4de349.1 KB - references/examples.md
fbadc3b7686.3 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from Kotlin/kotlin-agent-skills8
Model Kotlin persistence code correctly for Spring Data JPA and Hibernate. Covers entity design, identity and equality, uniqueness constraints, relationships, fetch plans, and common ORM (Object-Relational Mapping) traps specific to Kotlin. Use when creating or reviewing JPA (Java Persistence API) e
Migrates Kotlin Multiplatform (KMP) projects to Android Gradle Plugin 9.0+. Handles plugin replacement (com.android.kotlin.multiplatform.library), module splitting, DSL migration, and the new default project structure. Use when upgrading AGP, when build fails due to KMP+AGP incompatibility, or when
Migrate KMP projects from CocoaPods (kotlin("native.cocoapods")) to Swift Package Manager (swiftPMDependencies DSL) — replaces pod() with swiftPackage(), transforms cocoapods.* imports to swiftPMImport.*, and reconfigures the Xcode project.
Load when porting, converting, or reimplementing a single Gradle plugin as a Kotlin Toolchain local plugin, or when mapping Gradle plugin concepts (Task, Extension, project.version, dependsOn, -P properties, afterEvaluate) to Toolchain analogs. Skip for migrating a whole Gradle project or authoring
Load when migrating or converting an entire Gradle Kotlin project (build.gradle(.kts), wrapper, libs.versions.toml, buildSrc) to the Kotlin Toolchain, including rewriting CI and replacing Gradle plugins that have no native Toolchain equivalent. Skip for porting one Gradle plugin or general Toolchain
Migrate Kotlin (and Java) code from kotlinx.collections.immutable 0.3.x / 0.4.x to the latest 0.5.x. The 0.5.x line renames every copy-returning method on PersistentList / PersistentMap / PersistentSet / PersistentCollection to a participial form per KEEP-0459 (add→adding, removeAt→removingAt, set→r
Use when converting Java source files to idiomatic Kotlin, when user mentions "java to kotlin", "j2k", "convert java", "migrate java to kotlin", or when working with .java files that need to become .kt files. Handles framework-aware conversion for Spring, Lombok, Hibernate, Jackson, Micronaut, Quark
Load when building, running, testing, packaging, linting, or configuring a Kotlin/Java project with the Kotlin Toolchain (JetBrains' unified CLI, formerly Amper), when scaffolding a new or greenfield Kotlin project, or when the repo has project.yaml, module.yaml, or a ./kotlin wrapper. Skip for exis
Related mobile skillsscan passed
Swift 6.2 Approachable Concurrency — single-threaded by default, @concurrent for explicit background offloading, isolated conformances for main actor types. Use when adopting Swift 6.2 concurrency — offloading with @concurrent or resolving main-actor isolation.
Autonomous iOS bug fixer. (gstack)
Test iOS apps in a simulator with XcodeBuildMCP. Use when iOS changes need simulator evidence before handoff.
PostHog error tracking for React Native
Manages Firebase Remote Config templates, feature flags, loading strategies, and SDKs (Android, iOS). Use when downloading/deploying remoteconfig JSON templates, managing version history/feature flags, setting in-app defaults, fetchAndActivate(), real-time listeners, or SDK setup. Don't use for Fire
AWS SDK for Swift development patterns. Use when writing Swift code that uses AWS services via aws-sdk-swift package.