我做了很多关于如何用 Gradle 创建 fat jar 的研究。
但是,我不知道如何使用 Kotlin DSL 和插件。
我有这个代码:
plugins {
application
id("org.openjfx.javafxplugin") version "0.0.9"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
repositories {
mavenCentral()
}
dependencies {
implementation("javax.vecmath", "vecmath", "1.5.2")
implementation("org.apache.commons", "commons-csv", "1.8")
}
application {
mainModule.set("de.weisbrja")
mainClass.set("de.weisbrja.App")
}
javafx {
modules("javafx.controls")
}
modularity.disableEffectiveArgumentsAdjustment()
但我不知道如何为 fat jar list 指定主类。我遵循的教程是这样做的:
jar {
manifest {
attributes "Main-Class": "com.baeldung.fatjar.Application"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
但那是 Groovy DSL 而不是 Kotlin DSL,我对 Kotlin DSL 还不是很熟悉,所以我不知道如何将其转换为 Kotlin DSL。非常感谢帮助。
最佳答案
在 kotlin dsl (build.gradle.kts) 中尝试这个 Vanilla 解决方案
dependencies {
implementation(group="org.mycomp",name="foo",version="1.0")
}
tasks {
jar {
//package org.mycomp.foo inside the .jar file
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
}
}
或者你可以使用 shadowJar 插件plugins {
id("com.github.johnrengelman.shadow") version "7.0.0"
}
然后运行 ./gradlew :shadowJar
关于gradle - 如何使用 Kotlin DSL 和插件在 Gradle 中创建一个胖 Jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66796014/