问题描述
我对如何使用 Gradle 创建胖罐做了大量研究。 但是,我不知道如何使用 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()
但我不知道如何为胖罐清单指定主类。 我遵循的教程是这样做的:
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) 中试试这个原版解决方案
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