使用 Gradle 构建具有 Kotlin-DSL 依赖关系的 jar
Using Gradle to build a jar with dependencies with Kotlin-DSL
问题已经有了答案:how to include all the dependencies in a jar file 虽然它是针对 Groovy
我将 gradle 与 kotlin-dsl
一起使用,但代码不兼容。我尝试使用以下几种方法使其工作,包括:
tasks.withType<Jar> {
configurations["compileClasspath"].forEach { file: File ->
copy {
from(zipTree(file.absoluteFile))
}
}
}
虽然这行不通。那么如何在 gradle 中使用 kotlin-dsl
包含依赖项?
这将起作用:
tasks.withType<Jar>() {
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}
在 copy { ... }
中不需要,您应该在 JAR 任务本身上调用 from
。
注意:Gradle 不允许在解决后更改依赖项。这意味着只有在配置 dependencies { ... }
之后才能执行上面的块。
问题已经有了答案:how to include all the dependencies in a jar file 虽然它是针对 Groovy
我将 gradle 与 kotlin-dsl
一起使用,但代码不兼容。我尝试使用以下几种方法使其工作,包括:
tasks.withType<Jar> {
configurations["compileClasspath"].forEach { file: File ->
copy {
from(zipTree(file.absoluteFile))
}
}
}
虽然这行不通。那么如何在 gradle 中使用 kotlin-dsl
包含依赖项?
这将起作用:
tasks.withType<Jar>() {
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}
在 copy { ... }
中不需要,您应该在 JAR 任务本身上调用 from
。
注意:Gradle 不允许在解决后更改依赖项。这意味着只有在配置 dependencies { ... }
之后才能执行上面的块。