使用 Kotlin DSL 在 Gradle 中解压文件
Unzip file in Gradle using Kotlin DSL
我有一个 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 and Offical Gradle docs。
有些部分很明显,改为声明 val runtimeDir by extra("$buildDir/dependencies/fooBarRuntime")
,但最让我感到困惑的是 zip 依赖项和提取到已知位置供以后使用。
谁能告诉我 example/documentation?
更新:
我现在有这样的东西,而且似乎有效:
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)
}
}
这似乎有效:
通过 configurations.creating 验证 fooBarRuntime
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)
}
}
我有一个 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 and Offical Gradle docs。
有些部分很明显,改为声明 val runtimeDir by extra("$buildDir/dependencies/fooBarRuntime")
,但最让我感到困惑的是 zip 依赖项和提取到已知位置供以后使用。
谁能告诉我 example/documentation?
更新:
我现在有这样的东西,而且似乎有效:
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)
}
}
这似乎有效: 通过 configurations.creating 验证 fooBarRuntime 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)
}
}