I have an extremely basic custom build (Minecraft resource pack zipping and copying)
Directory layout
Project
- src (future Java/Kotlin sources for resource pack preprocessing)
- build (future Java/Kotlin class output folder, kept seperate from produced assets)
- rp (the 'src' folder for the resource pack assets, pre-processing.
- assets
- rp-out (the 'build' folder for the resource pack assets, post-processing.
- ResourcePack.zip
- ResourcePack
- variousAssetsToZip
and the following build.gradle.kts
plugins {
id("base")
}
tasks.create<Copy>("copy") {
description = "Basic copy"
group = "custom"
from("rp")
into("rp-out/${project.name}")
}
tasks.create<Zip>("zip") {
description = "Archives the resource pack output"
group = "Archive"
from("rp-out/${project.name}")
destinationDir = file("rp-out")
}
tasks.create<Delete>("cleanRP") {
group = "build"
delete {
file("rp-out")
file("rp-zip")
}
}
I expect that this would clean / delete either the folders rp-out, rp-zip themselves, or the contents.
But I'm unable to get the cleanRP task to delete the folder contents, it simply completes the task, without any seeming effect.
I'm a little familiar with gradle for Java projects, and this is the first Kotlin scripting I've done, but I have been moderately paying attention to conference talks.
How can I debug this effectively? Given the early stage of gradle kotlin-dsl How should I approach learning on my own?
(Also what's the solution to this problem?)
delete is a property of the task, and uses 'setter notation' to be set.
It accepts a Set, so using the kotlin setOf syntax, you can define a set of the "file like" types that Gradle supports.
Example:
tasks.create<Delete>("cleanRP") {
group = "rp"
delete = setOf (
"rp-out", "rp-zip"
)
}
You should use delete() configuration methods instead, so tasks can be correctly chained.
tasks.create<Delete>("cleanRP") {
group = "rp"
delete(
fileTree("rp-out"),
fileTree("rp-zip")
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With