Skip to main content
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 in WORKSPACE.rbs:
Supported versions are 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:
Supported Kotlin versions are 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 in WORKSPACE.rbs with java_repository (or the identical kotlin_repository alias):
Several at once, using 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

In BUILD.rbs, reference an external dependency with the @external:// form: the Maven coordinate with every ., -, and : replaced by _, followed by the version:
Local library targets are referenced the usual way: :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 a Main-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, so args takes its selectors.

java_lint

A lightweight, dependency-free linter for basic hygiene (tabs, trailing whitespace).

Kotlin rules

The Kotlin rules mirror the Java rules — same attributes, same dependency mechanism, same JUnit 5 / JaCoCo auto-inclusion for tests. Kotlin and Java targets can depend on each other freely since both produce JARs.

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 top-level main functions compile to a class named after the file: Main.kt becomes MainKt. If main is unset, the name is derived from the first source file; set it explicitly (fully qualified) when your code declares a package.

kotlin_test

Identical to java_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 (from kotlin/rules.rbs) — fast built-in checks: whitespace, line length (max_line_length, default 120), wildcard imports, and a Spring Boot open class check. Attributes: srcs, max_issues, max_line_length.
  • kt_lint (from @rbs//kotlin/lint.rbs) — runs real ktlint and/or detekt. Register the linters in WORKSPACE.rbs with register_kotlin_linters(), then:

Testing

Enable the shared JVM test dependencies once in WORKSPACE.rbs — this pre-installs JUnit 5 and the JaCoCo agent from Maven Central:
Then run tests with the standard commands (they work identically for java_test and kotlin_test):
Coverage thresholds declared on the target are enforced by 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.