Include kotlin standard in output jar

hello I am writing a simple kotlin application targeting the JVM using gradle I have no idea how to include kotlin so I can java -jar myJar.jar

my build.gradle

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.9.22'
    id "com.github.johnrengelman.shadow" version "7.1.2"
}

group = 'net.walksanator.uxnkt'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
jar {
    manifest {
        attributes 'Main-Class': 'net.walksanator.uxnkt.MainKt'
    }
}

test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(17)
}

You need to do one of two things.

  1. Include your dependencies in your jar file, along with a location of where to find them on the computer. IE, you need a list that says “I require org.jetbrains.kotlin:kotlin-stdlib, and I will look for it in C:\Users\myUser.m2\repository\org\jetbrains\kotlin”
  2. Use the Shadow plugin that you have in your build.gradle file to build a shaded jar. One of your Gradle tasks should be something like “shadowJar”, and using that will produce a jar file that includes the Kotlin standard library inside it.

Is that the same as a fat jar?

Yep, I just call it a shaded jar in this case because as far as I know, they’re two different names for the same thing, but specifically Gradle has the shadow plugin which creates shaded jars. Seems weird to talk about a shadow plugin creating fat jars, y’know? :stuck_out_tongue: