我有一个Groovy Gradle脚本,需要将其转换为Kotlin DSL。以下是源build.gradle的精简版本:
buildscript {
ext {
runtimeDir = "$buildDir/dependencies/fooBarRuntime"
}
}
...
configurations {
runtimeArchive
}
dependencies {
runtimeArchive "foo:bar:1.2.3@zip"
}
task unzip(type: Copy) {
configurations.runtimeArchive.asFileTree.each {
from(zipTree(it))
}
into runtimeDir
}
test.dependsOn unzip
test {
useJUnitPlatform()
environment "LD_LIBRARY_PATH", runtimeDir
}
我感到困惑的地方是找到有关如何通过Kotlin DSL进行操作的明确示例(我已经检查了Kotlin DSL docs和Offical Gradle docs。
某些部分是显而易见的,改为声明
val runtimeDir by extra("$buildDir/dependencies/fooBarRuntime")
,但最令我困扰的是zip依赖关系以及将其提取到已知位置以供以后使用。谁能指出我的示例/文档?
更新:
我现在有这样的东西,它似乎可以工作:
val fooBarRuntime by configurations.creating
val runtimeDir by extra("$buildDir/dependencies/fooBarRuntime")
dependencies {
fooBarRuntime("foo", "bar", "1.2.3" , ext="zip")
}
tasks.withType<Test> {
dependsOn("unzip")
}
tasks.register("unzip") {
fooBarRuntime.asFileTree.forEach {
unzipTo(File(runtimeDir), it)
}
}
最佳答案
这似乎可行:
val fooBarRuntime通过configurations.creating
val runtimeDir by extra(“$ buildDir / dependencies / fooBarRuntime”)
dependencies {
fooBarRuntime("foo", "bar", "1.2.3" , ext="zip")
}
tasks.withType<Test> {
dependsOn("unzip")
}
tasks.register("unzip") {
fooBarRuntime.asFileTree.forEach {
unzipTo(File(runtimeDir), it)
}
}
关于gradle - 使用Kotlin DSL在Gradle中解压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200514/