Reputation: 586
I have a Groovy Gradle script that I need to convert over to Kotlin DSL. Below is an abridged version of the source 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
}
Where I am coming unstuck is finding a clear example on how to do this via Kotlin DSL (I have check the Kotlin DSL docs and Offical Gradle docs.
Some part are obvious, declare val runtimeDir by extra("$buildDir/dependencies/fooBarRuntime")
instead, but what's mostly tripping me up is the zip dependency and the extraction into a known location for later use.
Can anyone point me towards an example/documentation?
Update:
I've now got something like this, and it seems to work:
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)
}
}
Upvotes: 3
Views: 2252
Reputation: 586
This seems to work: 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)
}
}
Upvotes: 1