quarkusio/quarkus · error · RuntimeException

Unable to invoke Kotlin compiler.

Error message

Unable to invoke Kotlin compiler. 

What it means

KotlinCompilationProvider.compile throws this RuntimeException when the Kotlin compiler execution returns an exit code other than OK or COMPILATION_ERROR — i.e. the compiler could not even run properly (crashed, OOM, bad toolchain), as opposed to ordinary compile errors in user code. Collected compiler errors are appended to the message.

Source

Thrown at extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java:99

        compilerArguments.setDestination(context.getOutputDirectory().getAbsolutePath());
        compilerArguments.setFreeArgs(filesToCompile.stream().map(File::getAbsolutePath).collect(Collectors.toList()));

        final K2JVMCompiler compiler = new K2JVMCompiler();
        final Collection<String> compilerOptions = context.getCompilerOptions(KOTLIN_PROVIDER_KEY);

        if (compilerOptions != null && !compilerOptions.isEmpty()) {
            compiler.parseArguments(compilerOptions.toArray(new String[0]), compilerArguments);
        }

        final SimpleKotlinCompilerMessageCollector messageCollector = new SimpleKotlinCompilerMessageCollector();
        final ExitCode exitCode = compiler.exec(messageCollector, new Services.Builder().build(), compilerArguments);

        if (exitCode != ExitCode.OK) {
            final String errors = String.join("\n", messageCollector.getErrors());

            if (exitCode != ExitCode.COMPILATION_ERROR) {
                throw new RuntimeException("Unable to invoke Kotlin compiler. " + errors);
            } else if (messageCollector.hasErrors()) {
                throw new RuntimeException("Compilation failed. " + errors);
            }
        }
    }

    private static class SimpleKotlinCompilerMessageCollector implements MessageCollector {

        private final List<String> errors = new ArrayList<>();

        @Override
        public void clear() {
        }

        @Override
        public boolean hasErrors() {
            return !errors.isEmpty();
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Read the appended compiler errors in the message for the root cause (often OOM or version conflict).
  2. Align the Kotlin version: use the Kotlin version matching your Quarkus BOM (quarkus.platform.native/kotlin recommendations) in the Kotlin Maven/Gradle plugin and stdlib.
  3. Increase build JVM memory (MAVEN_OPTS/gradle jvmargs, e.g. -Xmx2g or more) if the compiler is dying from OOM.
  4. Stop stale Kotlin daemons (kill KotlinCompileDaemon processes) or run with kotlin.compiler.execution.strategy=in-process, then rebuild clean.

Example fix

// before (mismatched versions)
<artifact>kotlin-maven-plugin</artifact>
<version>1.9.0</version> <!-- Quarkus BOM expects 2.0.x -->
// after: use the version Quarkus recommends
<kotlin.version>2.0.21</kotlin.version>
export MAVEN_OPTS="-Xmx3g"
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify kotlin compiler toolchain alignment before compiling
String bomKotlin = "2.0.21"; // version from quarkus BOM
String pluginKotlin = kotlinPluginVersion;
if (!bomKotlin.equals(pluginKotlin))
    log.warn("Kotlin version mismatch: plugin={}, expected={}", pluginKotlin, bomKotlin);
if (Runtime.getRuntime().maxMemory() < 2L * 1024 * 1024 * 1024)
    log.warn("Low build JVM heap (-Xmx<2g); Kotlin compiler may fail");

Try / catch

try {
    compilationProvider.compile(context);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unable to invoke Kotlin compiler")) {
        log.error("Kotlin compiler failed to run (not a compile error): check version alignment, heap, daemon", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Building a Quarkus app with Kotlin sources where kotlinc's exec returns an abnormal exit code — e.g. incompatible kotlin-compiler version on the classpath vs. the Kotlin Gradle/Maven plugin, JVM crash or OutOfMemory during compilation, or corrupted Kotlin toolchain/daemon state.

Common situations: Kotlin stdlib/compiler version mismatches after upgrading the Quarkus BOM; build JVM with too little heap for the Kotlin compiler; Kotlin daemon crashes; mixing Kotlin plugin versions not aligned with the compiler embedding used by Quarkus.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/49a770ebcd3e63f3. Report an issue: GitHub.