Kotlin 如何在gradle中扩展现有任务?
我创建了一个新任务Kotlin 如何在gradle中扩展现有任务?,kotlin,gradle,executable-jar,gradle-kotlin-dsl,Kotlin,Gradle,Executable Jar,Gradle Kotlin Dsl,我创建了一个新任务jarWithDependencies,以创建一个可以执行的jar文件。它正确地打包了所有依赖项,但实际上它不包含我自己的代码,因此无法运行,因为它找不到我的主文件。如果我改为修改现有的jar任务,它可以正常工作,但我已经丢失了标准jar任务 我假设标准的jar任务做了我的任务没有做的事情。我可以让我的任务扩展标准jar任务吗。比如子任务之类的。这似乎很简单,但我找不到 以下是我在build.gradle中配置jarWithDependencies任务的方法 val jarWi
jarWithDependencies
,以创建一个可以执行的jar文件。它正确地打包了所有依赖项,但实际上它不包含我自己的代码,因此无法运行,因为它找不到我的主文件。如果我改为修改现有的jar
任务,它可以正常工作,但我已经丢失了标准jar任务
我假设标准的jar
任务做了我的任务没有做的事情。我可以让我的任务扩展标准jar
任务吗。比如子任务之类的。这似乎很简单,但我找不到
以下是我在build.gradle中配置jarWithDependencies
任务的方法
val jarWithDependencies by tasks.creating(Jar::class) {
description = "Jar with all dependencies"
group = "build"
archiveBaseName.set(archiveBaseName.get() + "-with-dependencies")
configurations.compileClasspath.get().forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "de.lehrbaum.bot.translate.MainKt"
}
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "de.lehrbaum.bot.translate.MainKt"
}
configurations.compileClasspath.get().forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}