Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.util.*
open class PropertiesWriter : DefaultTask() {
@get:Input
val key = project.objects.property<String>().convention("someProperty")
@get:Input
val value = project.objects.property<String>().convention("someValue")
@get:OutputFile
val outputFile: Provider<RegularFile> = project.layout.buildDirectory.file("out.properties")
@TaskAction
fun writeFile() {
outputFile.get().asFile.writeText("${key.get()}=${value.get()}")
}
}
open class AwesomeTask : DefaultTask() {
@get:Input
val propertyName: Property<String> = project.objects.property<String>().convention("someProperty")
@get:Input
val value: Property<String> = project.objects.property()
@TaskAction
fun printProperty() {
println(value.get())
}
}
val writeProperties by tasks.registering(PropertiesWriter::class)
val readProperties by tasks.registering(AwesomeTask::class) {
value.set(writeProperties.map {
Properties().run {
load(writeProperties.get().outputFile.get().asFile.inputStream())
get(propertyName.get()) as String
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment