对于这个问题,已经有了一个答案:how to include all the dependencies in a jar file,尽管它是针对Groovy的
我在kotlin-dsl中使用gradle,代码不兼容。我试着用以下几种方法使它发挥作用:
tasks.withType<Jar> {
configurations["compileClasspath"].forEach { file: File ->
copy {
from(zipTree(file.absoluteFile))
}
}
}虽然这不管用。那么,如何在gradle中使用kotlin-dsl来包含依赖关系呢?
发布于 2017-09-11 14:14:59
这将起作用:
tasks.withType<Jar>() {
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}在copy { ... }中没有必要,您应该调用JAR任务本身的from。
注意: Gradle不允许在解决依赖关系后更改它们。这意味着,只有在配置了dependencies { ... }之后,才应该执行上面的块。
发布于 2022-08-17 12:42:59
我的案子
withType<Jar> {
enabled = true
isZip64 = true
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("$project.jar")
from(sourceSets.main.get().output)
dependsOn(configurations.compileClasspath)
from({
configurations.compileClasspath.get().filter {
it.name.endsWith("jar")
}.map { zipTree(it) }
}) {
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}
}https://stackoverflow.com/questions/46157338
复制相似问题