正如标题所述,我想知道如何修改它gradle.build.kts
以便创建一个独特jar
的所有依赖项(包括kotlin lib)的任务.
我在Groovy中找到了这个示例:
//create a single Jar with all dependencies task fatJar(type: Jar) { manifest { attributes 'Implementation-Title': 'Gradle Jar File Example', 'Implementation-Version': version, 'Main-Class': 'com.mkyong.DateUtils' } baseName = project.name + '-all' from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } with jar }
但我不知道如何在kotlin中写出来,除了:
task("fatJar") { }
FrontierPsyc.. 26
这是一个不使用插件的版本,更像是Groovy版本.
import org.gradle.jvm.tasks.Jar val fatJar = task("fatJar", type = Jar::class) { baseName = "${project.name}-fat" manifest { attributes["Implementation-Title"] = "Gradle Jar File Example" attributes["Implementation-Version"] = version attributes["Main-Class"] = "com.mkyong.DateUtils" } from(configurations.runtime.map({ if (it.isDirectory) it else zipTree(it) })) with(tasks["jar"] as CopySpec) } tasks { "build" { dependsOn(fatJar) } }
这里也解释了
这是一个不使用插件的版本,更像是Groovy版本.
import org.gradle.jvm.tasks.Jar val fatJar = task("fatJar", type = Jar::class) { baseName = "${project.name}-fat" manifest { attributes["Implementation-Title"] = "Gradle Jar File Example" attributes["Implementation-Version"] = version attributes["Main-Class"] = "com.mkyong.DateUtils" } from(configurations.runtime.map({ if (it.isDirectory) it else zipTree(it) })) with(tasks["jar"] as CopySpec) } tasks { "build" { dependsOn(fatJar) } }
这里也解释了