JetBrains/kotlin
Maven plugin
Active contributors: Alexander Udalov, Dmitriy Novozhilov, Filipp Zhinkin
libraries/kotlin-maven-plugin/ is the Apache Maven integration for Kotlin: a Maven Mojo that compiles .kt and .java sources, plus per-compiler-plugin Maven wrappers (kotlin-maven-allopen, kotlin-maven-noarg, kotlin-maven-serialization, etc.). Unlike most of this repository, the Maven plugin builds with Maven, not Gradle.
Purpose
Let Kotlin projects build with Maven without leaving the Maven idiom. Provide goals (compile, test-compile, js, metadata) wired into Maven's lifecycle, plus dedicated plugins that wrap each compiler plugin for use from <plugin> declarations.
Directory layout
libraries/
├── kotlin-maven-plugin/ Core Mojo
├── kotlin-maven-plugin-test/ Tests
├── kotlin-maven-allopen/ allopen wrapper
├── kotlin-maven-noarg/ noarg wrapper
├── kotlin-maven-serialization/ kotlinx.serialization wrapper
├── kotlin-maven-sam-with-receiver/
├── kotlin-maven-lombok/
├── kotlin-maven-power-assert/
├── kotlin-maven-dataframe/
├── pom.xml Parent POM
├── mvnw, mvnw.cmd Maven Wrapper
└── maven-settings.xmlKey abstractions
| Type | Where | Role |
|---|---|---|
K2JVMCompileMojo |
libraries/kotlin-maven-plugin/.../K2JVMCompileMojo.kt |
The compile and test-compile goal Mojos. |
KotlinCompileMojoBase |
libraries/kotlin-maven-plugin/.../KotlinCompileMojoBase.kt |
Shared base for all compile goals. |
KotlinJsCompileMojo |
libraries/kotlin-maven-plugin/.../KotlinJsCompileMojo.kt |
JS goal. |
KotlinMetadataCompileMojo |
libraries/kotlin-maven-plugin/.../KotlinMetadataCompileMojo.kt |
Metadata-only goal. |
Goals
The plugin exposes a small number of Maven goals:
| Goal | Phase | Purpose |
|---|---|---|
kotlin:compile |
compile |
Compile production sources. |
kotlin:test-compile |
test-compile |
Compile test sources. |
kotlin:js |
n/a | Compile to JS (legacy). |
kotlin:metadata |
n/a | Compile a metadata module. |
Per-plugin wrappers
For every compiler plugin that benefits from Maven-level configuration, there is a small Maven wrapper. They all share the same shape: a Mojo extension that contributes the right -Xplugin=... argument with the plugin's options.
| Wrapper | Wraps | When to use |
|---|---|---|
kotlin-maven-allopen |
plugins/allopen/ |
Spring/JPA: open declarations matching annotations. |
kotlin-maven-noarg |
plugins/noarg/ |
JPA: synthesize no-arg constructors. |
kotlin-maven-serialization |
plugins/kotlinx-serialization/ |
kotlinx.serialization. |
kotlin-maven-sam-with-receiver |
plugins/sam-with-receiver/ |
SAM conversion with extension receiver. |
kotlin-maven-lombok |
plugins/lombok/ |
Lombok interop. |
kotlin-maven-power-assert |
plugins/power-assert/ |
Power-assert. |
kotlin-maven-dataframe |
plugins/kotlin-dataframe/ |
DataFrame's compiler plugin. |
How a Maven build works
graph LR
POM["pom.xml<br/>(kotlin-maven-plugin)"] --> Mojo["K2JVMCompileMojo"]
Mojo --> Args["construct CompilerArguments"]
Args --> Compiler["embedded Kotlin compiler"]
Compiler --> Cls["target/classes"]The Mojo runs the compiler in-process (no daemon), since Maven's lifecycle does not naturally fit a long-running daemon. This makes Maven-based builds slower than Gradle-based ones at scale, but simpler.
Java/Kotlin coexistence
The Maven plugin uses Maven's standard compile and test-compile phase wiring, which means it must coexist with the maven-compiler-plugin (Java). The convention is to bind kotlin:compile before maven-compiler-plugin:compile in the lifecycle so Kotlin sees Java-only sources and javac can pick up Kotlin's outputs.
Tests
libraries/kotlin-maven-plugin-test/ runs end-to-end Maven builds against representative POMs. Like the KGP integration tests, these are slow (they spawn full Maven processes).
Integration points
- Consumed by: any project using Maven for builds. Common in older corporate codebases and in some library ecosystems.
- Backed by: the embedded Kotlin compiler (the same compiler used everywhere else, configured for in-process execution).
- Plugins: each
kotlin-maven-*artifact wraps aplugins/*compiler plugin.
Where to start
For a new compile-time option exposed via Maven: add it to the relevant Mojo (under libraries/kotlin-maven-plugin/), update pom.xml to register it, and add a test under libraries/kotlin-maven-plugin-test/.
For a new compiler-plugin Maven wrapper: copy an existing one (e.g., kotlin-maven-noarg/) and adapt its pom.xml and Mojo descriptor.
See KGP for the Gradle counterpart and the plugins overview for the underlying compiler plugins.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.