Java and Kotlin with Elide
Run Java or Kotlin with the bundled JDK and compilers. Create a small app, run its tests, then add Maven dependencies.
On this page
Install Elide, then choose a template below. Each creates a new project directory with a program and a test.
Kotlin
mkdir hello-kotlin
cd hello-kotlin
elide init --plain --skip-defaults --skip-run --template ktjvm
elide run
Edit src/main/com/example/Hello.kt, then run elide run again.
Java
mkdir hello-java
cd hello-java
elide init --plain --skip-defaults --skip-run --template java
elide run
Edit src/main/com/example/Hello.java, then run elide run again.
Both programs print:
Hello Elide!
Run the generated test with elide test. To use a library, declare its Maven dependency in elide.pkl, then:
elide install
elide test
elide run
Already have a project? Keep Maven/Gradle and use Elide's compiler or JDK, or migrate your build to elide.pkl.
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.javaFormat 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.ktFormat 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 build
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.
amends "elide:project.pkl"
import "elide:Jvm.pkl" as Jvm
import "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" }
}
}
The default build compiles non-test source sets and produces their configured artifacts. Tests compile against main outputs and execute with JUnit Platform.
elide project info # Confirm the detected project and entrypoint
elide install # Resolve declared Maven dependencies
elide build --inspect # List generated tasks and task options
elide build # Compile main sources and produce default artifacts
elide test # Compile tests and run them with JUnit Platform
elide run # Build as needed, then launch shop.Main
Add a Kotlin test for the example
package shop
import java.math.BigDecimal
import kotlin.test.Test
import 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)
}
}
Use elide testfor the full suite. Build-task options can select an individual JUnit class when you need a tighter feedback loop.
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.MainGenerate API docs
Generate Javadoc using the standard command-line options.
elide javadoc -- -d docs src/main/java/app/Main.javaInspect bytecode
Disassemble a compiled class while debugging build output.
elide javap -- -classpath target -c app.MainBuild a native executable
Compile a JVM application ahead of time to a native executable.
elide native-image -- -cp app.jar app.Main
Programs run on the bundled JDK with the Kotlin standard library, bundled kotlinx libraries, JUnit for tests and Elide's annotations; see JVM APIs. There is no Elide runtime API, no calls into JavaScript or Python, and no OpenTelemetry API, agent or trace context; add the OpenTelemetry Java SDK yourself, and see OpenTelemetry for the spans elide build and elide test export.
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.
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())
},
)
}
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()
);
}
}
elide runWas this page helpful?