# Elide for Kotlin users

> Switching from kotlinc and Gradle to Elide: running Kotlin files directly, what changes in builds, dependencies and tests, benchmarks and trade-offs.

Elide bundles Kotlin 2.5.0-Beta2 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`, `elide java` and `elide jar` run the Kotlin and JDK tools. 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 need no
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` | `elide build` with a [managed or custom toolchain](https://elide.help/docs/toolchain/jvm/kotlinc#choose-a-toolchain); `elide kotlinc --kapt-sources` for CLI/Bazel. |
| `ksp` | `elide kotlinc --ksp-output` (command line and Bazel); not in `elide build`. |

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

## Benchmarks

No benchmarks are 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.
- kotlinx.serialization, coroutines, Power Assert and Metro are enabled without configuration. atomicfu is on too, with its runtime library.
- `ManagedKotlinToolchain` builds a project with another Kotlin version, prereleases included.
- Workspace members can read a sibling's `internal` declarations with `project("core").friend()`.

## Weaknesses

- No Gradle support: `elide build` does not read `build.gradle.kts`, and Gradle plugins have no equivalent.
- KSP is not scheduled in project builds; kapt needs a [managed or custom toolchain](https://elide.help/docs/toolchain/jvm/kotlinc#choose-a-toolchain),
  not the embedded compiler. `elide kotlinc --kapt-sources` and `--ksp-output` remain for CLI and Bazel.
- The bundled compiler is Kotlin 2.5.0-Beta2, 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)
- [JVM APIs](https://elide.help/docs/api-jvm)
- [Kotlin Compiler](https://elide.help/docs/toolchain/jvm/kotlinc)
- [Adopt an Existing Project](https://elide.help/docs/toolchain/usage/adopt)
