Launch4j Gradle Configuration.
Launch4j wrap a java jar into an exe.
Add the following code to build.gradle.kts to enable launch4j:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
application
kotlin("jvm") version "1.3.50"
id("com.github.johnrengelman.shadow") version "5.1.0"
id("edu.sc.seis.launch4j") version "2.4.6"
}
group = "wumo"
version = "0.0.1"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation("org.junit.jupiter:junit-jupiter:5.+")
tasks.test {
useJUnitPlatform()
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClassName = "MyAppKt"
}
launch4j {
val shadowJar by tasks.getting(ShadowJar::class)
copyConfigurable = shadowJar.outputs.files
jar = "lib/${shadowJar.archiveFileName.get()}"
jreMinVersion = "1.8.0"
headerType = "console" // or "gui"
chdir = ""
}Note:
launch4jsearches inregistryforHKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JRE\1.XX@JavaHomeorHKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK\1.XX@JavaHometo determine the java executable path. Manually add this registry if you don’t have one.headerTypeshould change toguiif you are developing a gui app.chdir=""ensures the working directory won’t be changed if you launch the app from different folder.chdir="."will change the working directory to the path of your app.