rbs builds Java and Kotlin projects hermetically: it downloads an OpenJDK (Eclipse
Temurin) and, for Kotlin, the JetBrains compiler, resolves dependencies from Maven
Central, and produces self-contained launchers that bundle the JARs and the runtime.
No system JDK, no Gradle or Maven installation.
Set up the toolchains
Java
Declare the JDK inWORKSPACE.rbs:
17.0.11 (LTS, default) and 21.0.3. Keep the toolchain name
java — the Java rules resolve it by that name. When cross-compiling, a host JDK is
downloaded as well so javac runs natively on the build machine.
Kotlin
Kotlin compiles to JVM bytecode and needs a Java toolchain, so declare both — Java first:2.0.21 (default), 1.9.25, 1.9.24, and 1.9.23.
Keep the toolchain names java and kotlin — the rules resolve them by those names.
Kotlin targets JVM 17 bytecode, and the Kotlin standard library is bundled into your
targets automatically.
Declare Maven dependencies
External JVM dependencies come from Maven Central. Declare them inWORKSPACE.rbs
with java_repository (or the identical kotlin_repository alias):
group:artifact:version specs:
rbs downloads the JAR and POM, follows the POM to resolve transitive dependencies
recursively, and records everything in the workspace lockfile for instant repeat
builds.
Referencing dependencies in BUILD files
InBUILD.rbs, reference an external dependency with the @external:// form: the
Maven coordinate with every ., -, and : replaced by _, followed by the
version:
:my_lib within the package, or
//path/to/pkg:my_lib across packages.
Kotlin convenience helpers
For common Kotlin libraries,@rbs//kotlin/dependencies.rbs provides one-line
helpers: kotlin_stdlib(), kotlin_reflect(), kotlin_coroutines(),
kotlin_serialization(), and kotlin_all_dependencies(). Default versions can be
pinned workspace-wide with configure_kotlin_versions().
Java rules
java_library
Compiles sources into a JAR that other targets can depend on. External dependencies propagate transitively to dependents.java_binary
Builds an executable application: compiles the sources, packages a JAR with aMain-Class manifest, and emits a launcher that runs it on the bundled JDK.
java_test
Defines a JUnit 5 test target. The JUnit 5 framework (Jupiter, Platform Launcher and Console) and the JaCoCo coverage agent are added automatically — you only declare the code under test. Tests run through the JUnit Platform Console Launcher, soargs
takes its selectors.
java_lint
A lightweight, dependency-free linter for basic hygiene (tabs, trailing whitespace).Kotlin rules
kotlin_library and kotlin_binary
kotlin_library takes srcs, deps, runtime_deps, and resources;
kotlin_binary adds main and javaopts — the same shapes as their Java
counterparts.
kotlin_test
Identical tojava_test (including test_main, Console Launcher args, and the
min_*_coverage thresholds), with JUnit 5 and the JaCoCo agent auto-included:
Linting Kotlin
Two options exist:kotlin_lint(fromkotlin/rules.rbs) — fast built-in checks: whitespace, line length (max_line_length, default 120), wildcard imports, and a Spring Bootopen classcheck. Attributes:srcs,max_issues,max_line_length.kt_lint(from@rbs//kotlin/lint.rbs) — runs real ktlint and/or detekt. Register the linters inWORKSPACE.rbswithregister_kotlin_linters(), then:
Testing
Enable the shared JVM test dependencies once inWORKSPACE.rbs — this pre-installs
JUnit 5 and the JaCoCo agent from Maven Central:
java_test and
kotlin_test):
rbs coverage — a target
below its threshold fails.
Protocol Buffers
Java and Kotlin both have proto bindings —java_proto_library (from
@rbs//java/proto.rbs) and kotlin_proto_library (from @rbs//kotlin/proto.rbs) —
which generate code from a proto_library and auto-include the protobuf runtime (and
gRPC libraries with enable_grpc = True). See
Other languages for the shared proto toolchain setup and
a full example.
Editor support
Java and Kotlin language support in the ReasonOS editor is provisioned automatically
when JVM sources are detected in your workspace — no build-file configuration needed.
See the editor language support documentation for details.