5

这个问题已经有了答案:如何在 jar 文件中包含所有依赖项,尽管它是针对 Groovy 的

我正在使用 gradlekotlin-dsl并且代码不兼容。我尝试使用几种方法使其工作,包括:

tasks.withType<Jar> {
    configurations["compileClasspath"].forEach { file: File ->
        copy {
            from(zipTree(file.absoluteFile))
        }
    }
}

虽然这不起作用。那么如何kotlin-dsl在 gradle 中包含依赖项呢?

4

1 回答 1

6

这将起作用:

tasks.withType<Jar>() {
    configurations["compileClasspath"].forEach { file: File ->
        from(zipTree(file.absoluteFile))
    }
}

中没有必要copy { ... },您应该调用fromJAR 任务本身。

注意:Gradle 不允许在解析后更改依赖项。这意味着上面的块只能在dependencies { ... }配置后执行。

于 2017-09-11T14:14:59.373 回答