Created
November 27, 2019 00:33
-
-
Save melix/314080a15e3fd9e435ce20d825a32bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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