我有一个 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 文档和 Offical Gradle 文档。
有些部分是显而易见的,而是声明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 by configuration.create 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)
}
}