-- Leo's gemini proxy

-- Connecting to republic.circumlunar.space:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Building an all-in-one Jar in Gradle with the Kotlin DSL


To build a "fat" Jar of your Java or Kotlin project that contains all the dependencies within a single file, you can use the shadow Gradle plugin.


I found it hard to find clear documentation on how it works using the Gradle Kotlin DSL (with a build.gradle.kts instead of build.gradle) so here is how I did it:


shadow


$ cat build.gradle.kts
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
   kotlin("jvm") version "1.3.41"
   id("com.github.johnrengelman.shadow") version "5.1.0"
}

repositories {
   mavenCentral()
}

dependencies {
   implementation(kotlin("stdlib"))
}

tasks.withType<ShadowJar>() {
   manifest {
       attributes["Main-Class"] = "HelloKt"
   }
}

$ cat src/main/kotlin/Hello.kt
fun main() {
   println("Hello!")
}

$ gradle wrapper --gradle-version 5.5
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

$ ./gradlew shadowJar
BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed

$ java -jar build/libs/hello -all.jar
Hello!


Originally posted at 2019-07-12 13:55:56+00:00. Automatically generated from the original post : apologies for the errors introduced.


original post

-- Response ended

-- Page fetched on Sun May 19 07:24:00 2024