Java and Kotlin with Elide

Elide provides the JVM, compilers, dependency resolver, test runner, formatters, and packaging tools needed to take mixed Java and Kotlin sources from checkout to a runnable artifact.

Mixed source setsMaven dependenciesJUnit PlatformJARs & native images

Choose a Java or Kotlin workflow

Call a bundled language tool directly when you have one focused job, or use an Elide project when dependencies, tests, and outputs need to be shared. Both approaches use the same binary.

Java

Use Elide anywhere you would normally reach for the JDK compiler or Google Java Format. Standard tool arguments go after the -- separator.

  • Compile Java sources

    Produce class files with familiar javac flags—useful in a script, CI job, or an existing source tree.

    elide javac -- -d target src/main/java/app/Main.java
  • Format Java code

    Apply Google Java Format in place without installing or versioning a separate formatter.

    elide javaformat -- --replace src/main/java

Kotlin

Use the bundled Kotlin compiler and ktfmt directly, or let an Elide project coordinate Kotlin with Java and Maven dependencies.

  • Compile Kotlin sources

    Compile Kotlin to JVM bytecode with kotlinc-compatible options and no separate compiler installation.

    elide kotlinc -- -d target src/main/kotlin/app/Main.kt
  • Format Kotlin code

    Run the bundled ktfmt version locally or in CI so formatting stays reproducible across machines.

    elide ktfmt -- src/main/kotlin

When it becomes a project

These commands work across Java-only, Kotlin-only, and mixed JVM projects. Project configuration supplies the source sets, dependencies, entrypoint, and desired outputs.

  • Resolve Maven dependenciesInstall the packages declared by the project and assemble its JVM classpaths.elide install
  • Build a JVM projectCompile configured Java and Kotlin source sets and produce their artifacts.elide build
  • Run tests and coverageCompile test sources and execute Java or Kotlin tests with JUnit Platform.elide test
  • Package a JARUse the embedded JAR tool directly, or declare a JAR artifact for repeatable builds.elide jar
  • Build a containerTurn a configured JVM application into a container image with the embedded Jib builder.elide jib

Configure a mixed JVM project

This project declares one Java entrypoint, mixed-language main and test source sets, and three publishable JAR artifacts. Java and Kotlin share the same source-set classpaths automatically.

elide.pkl
pkl
amends "elide:project.pkl"import "elide:Jvm.pkl" as Jvmimport "elide:Sources.pkl" as Sources
name = "order-report"
jvm {  main = "shop.Main"}
sources {  ["main"] = new Sources.SourceSetSpec {    paths {      "src/main/kotlin/**/*.kt"      "src/main/java/**/*.java"    }  }  ["test"] = new Sources.SourceSetSpec {    paths {      "src/test/kotlin/**/*.kt"      "src/test/java/**/*.java"    }  }}
artifacts {  ["app"] = new Jvm.Jar {    name = "order-report"    main = "shop.Main"    sources { "main" }  }  ["sources"] = new Jvm.SourceJar {    sources { "main" }  }  ["docs"] = new Jvm.JavadocJar {    sources { "main" }  }}
NORMALelide.pklutf-8 · pkl · 38L
main selects the application entrypoint
main and test may each mix .java and .kt files
test source sets inherit compiled main classes
artifact names become addressable build tasks

Build, test, and run

The default build compiles non-test source sets and produces their configured artifacts. Tests compile against main outputs and execute with JUnit Platform.

bash
elide project info       # Confirm the detected project and entrypointelide install            # Resolve declared Maven dependencieselide build --inspect    # List generated tasks and task optionselide build              # Compile main sources and produce default artifactselide test               # Compile tests and run them with JUnit Platformelide run                # Build as needed, then launch shop.Main
Add a Kotlin test for the example
src/test/kotlin/shop/OrderTotalsTest.kt
kotlin
package shop
import java.math.BigDecimalimport kotlin.test.Testimport kotlin.test.assertEquals
class OrderTotalsTest {  @Test  fun `summarizes quantities and prices`() {    val summary = OrderTotals.summarize(      listOf(        LineItem("paper", 3, BigDecimal("7.50")),        LineItem("ink", 2, BigDecimal("18.25")),      ),    )
    assertEquals(5, summary.itemCount)    assertEquals(BigDecimal("59.00"), summary.subtotal)  }}
NORMALsrc/test/kotlin/shop/OrderTotalsTest.ktutf-8 · kotlin · 20L

Use elide testfor the full suite. Build-task options can select an individual JUnit class when you need a tighter feedback loop.

Embedded JVM tools

Elide also exposes the rest of its JVM toolchain directly. Prefix the familiar tool with elide, then put its native arguments after the separator.

  • Run compiled classes

    Launch a JVM entrypoint with the bundled Java runtime.

    elide java -- -cp target app.Main
  • Generate API docs

    Generate Javadoc using the standard command-line options.

    elide javadoc -- -d docs src/main/java/app/Main.java
  • Inspect bytecode

    Disassemble a compiled class while debugging build output.

    elide javap -- -classpath target -c app.Main
  • Build a native executable

    Compile a JVM application ahead of time with GraalVM Native Image.

    elide native-image -- -cp app.jar app.Main

Call Kotlin from Java

This example puts a Kotlin model and calculation beside a Java entrypoint in one main source set. Elide compiles both languages, connects their classes, and runs the Java entrypoint.

src/main/kotlin/shop/OrderTotals.kt
kotlin
package shop
import java.math.BigDecimal
data class LineItem(  val sku: String,  val quantity: Int,  val unitPrice: BigDecimal,)
data class OrderSummary(  val itemCount: Int,  val subtotal: BigDecimal,)
object OrderTotals {  @JvmStatic  fun summarize(lines: List<LineItem>): OrderSummary = OrderSummary(    itemCount = lines.sumOf { it.quantity },    subtotal = lines.fold(BigDecimal.ZERO) { total, line ->      total + line.unitPrice.multiply(line.quantity.toBigDecimal())    },  )}
NORMALsrc/main/kotlin/shop/OrderTotals.ktutf-8 · kotlin · 24L
src/main/java/shop/Main.java
java
package shop;
import java.math.BigDecimal;import java.util.List;
public final class Main {  public static void main(String[] args) {    var lines = List.of(        new LineItem("paper", 3, new BigDecimal("7.50")),        new LineItem("ink", 2, new BigDecimal("18.25")),        new LineItem("labels", 4, new BigDecimal("3.10"))    );
    var summary = OrderTotals.summarize(lines);
    System.out.printf(        "%d items · $%s subtotal%n",        summary.getItemCount(),        summary.getSubtotal()    );  }}
NORMALsrc/main/java/shop/Main.javautf-8 · java · 22L
elide run
9 items · $71.40 subtotal

Where to go next