Skip to content

Instantly share code, notes, and snippets.

@melix
Created November 27, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melix/314080a15e3fd9e435ce20d825a32bd7 to your computer and use it in GitHub Desktop.
Save melix/314080a15e3fd9e435ce20d825a32bd7 to your computer and use it in GitHub Desktop.
@CompileStatic
class PropertiesWriter extends DefaultTask {
@Input
final Property<String> key = project.objects.property(String).convention("someProperty")
@Input
final Property<String> value = project.objects.property(String).convention("someValue")
@OutputFile
final Provider<RegularFile> outputFile = project.layout.buildDirectory.file("out.properties")
@TaskAction
void writeFile() {
outputFile.get().asFile.write("${key.get()}=${value.get()}")
}
}
@CompileStatic
class AwesomeTask extends DefaultTask {
@Input
final Property<String> propertyName = project.objects.property(String).convention("someProperty")
@Input
final Property<String> value = project.objects.property(String)
@TaskAction
void printProperty() {
println(value.get())
}
}
def writeProperties = tasks.register("writeProperties", PropertiesWriter)
def readProperties = tasks.register("readProperties", AwesomeTask) {
value.set(writeProperties.map {
def props = new Properties()
props.load(writeProperties.get().outputFile.get().asFile.newInputStream())
props.get(propertyName.get())
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment