Kotlin Gradle include runtime when building jar

Viewed 468

I'm trying to include the kotlin runtime when building my jar with gradle. I cannot find an update to date thread anywhere online that shows how to do this.

Currently I have tried the following

plugins {
    kotlin("jvm") version "1.5.10"
}

repositories {
    mavenCentral()
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs = freeCompilerArgs + "-include-runtime"
        jvmTarget = "16"
    }
}

This builds the jar fine but doesn't include the runtime like I would expect. How can I configure gradle to do this?

1 Answers

You can use the shadowJar plugin. Add

    id("com.github.johnrengelman.shadow") version "7.0.0"

To your plugins, then run ./gradlew shadowJar to create a jar file in build/lib containing the kotlin runtime as well as any of your runtime dependencies

Related