# Elide for Kotlin users

> How Elide compares with kotlinc and Gradle, and what changes when you switch.

Elide bundles Kotlin 2.5.0-Beta1 and JDK 25 with a build tool, Maven dependency resolver, JUnit runner and ktfmt.

## Run the same code

A file with a `main` function compiles and runs directly:

```bash
elide run Main.kt
```

`elide kotlinc` runs the Kotlin compiler, and `elide java` and `elide jar` run the JDK tools, without a separate
install. Their arguments go after `--`:

```bash
elide kotlinc -- -version
elide kotlinc -- -d out Main.kt
```

A project is an `elide.pkl` file. Maven dependencies, kotlinx.serialization, kotlinx.coroutines and JUnit are
available without plugin blocks:

```bash
elide init --plain --skip-defaults --template ktjvm   # new project
elide install                                         # resolve Maven dependencies
elide build                                           # compile and assemble
elide test                                            # run JUnit tests
elide run                                             # run jvm.main
elide format -- src                                   # ktfmt
```

See [Java and Kotlin with Elide](https://elide.help/docs/jvm), [Kotlin Compiler](https://elide.help/docs/toolchain/jvm/kotlinc),
[Testing](https://elide.help/docs/toolchain/testing) and the [`elide.pkl` reference](https://elide.help/docs/elide-pkl-reference).

## What changes

| With kotlinc and Gradle | With Elide |
| --- | --- |
| Install a JDK and `kotlinc` | Nothing; both are bundled. |
| `kotlinc Main.kt -d out` | `elide kotlinc -- -d out Main.kt` |
| `build.gradle.kts` | `elide.pkl` |
| `kotlin("jvm") version "2.3.0"` | `kotlin { toolchain = new Kotlin.ManagedKotlinToolchain { version = "2.3.0" } }` |
| `kotlin("plugin.serialization")` | On by default ([`kotlin.features`](https://elide.help/docs/toolchain/jvm/kotlinc#plugins-and-features)). |
| Subprojects in `settings.gradle.kts` | `workspace { members { "core"; "app" } }` in the root `elide.pkl` |
| `./gradlew build`, `test`, `run` | `elide build`, `elide test`, `elide run` |
| Migrate a `./gradlew` build | `elide adopt`; see [Adopt an Existing Project](https://elide.help/docs/toolchain/usage/adopt). |
| `ktfmt` | `elide format` |
| IDE project import | `elide project export --format=intellij` |
| `kapt`, `ksp` | No equivalent. |

`ManagedKotlinToolchain` needs `import "elide:Kotlin.pkl" as Kotlin` and applies to project builds; `elide kotlinc`
always uses the bundled Kotlin.

## Benchmarks

No startup or serving benchmark is published for JVM programs in 1.6.0. For ahead-of-time builds, see
[Native Image](https://elide.help/docs/toolchain/jvm/native-image).

## Strengths

- One binary replaces the JDK, `kotlinc`, the Maven resolver, the JUnit launcher and ktfmt.
- `elide run Main.kt` compiles and runs a file with no project.
- kotlinx.serialization, coroutines, atomicfu, Power Assert and Metro are enabled without configuration.
- `ManagedKotlinToolchain` builds a project with another Kotlin version, prereleases included.
- Workspace members can read a sibling's `internal` declarations with `project("core").friend()`.
- `elide project export` writes a `pom.xml` or IntelliJ model for tools that need one.

## Weaknesses

- No Gradle support: `elide build` does not read `build.gradle.kts`, and Gradle plugins have no equivalent.
- KAPT and KSP are unsupported; Kotlin that uses Java-generated types must take them from an upstream source set.
- The bundled compiler is Kotlin 2.5.0-Beta1, a beta.
- `elide java` does not add `kotlin-stdlib` (`NoClassDefFoundError`), and `elide kotlinc -- -include-runtime`
  fails. Run with `elide run`, or package with a `Jvm.JvmApplication`
  ([JAR Assembly](https://elide.help/docs/toolchain/jvm/jar#runnable-application-distributions)).
- `elide adopt` is untested on multi-module and Android projects.

## Next steps

- [Java and Kotlin with Elide](https://elide.help/docs/jvm)
- [Kotlin Compiler](https://elide.help/docs/toolchain/jvm/kotlinc)
- [Adopt an Existing Project](https://elide.help/docs/toolchain/usage/adopt)
