Created
November 26, 2019 23:44
-
-
Save melix/60f480c7badf774ae2fa5298c86853f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* This file was generated by the Gradle 'init' task. | |
* | |
* This generated file contains a sample Java Library project to get you started. | |
* For more details take a look at the Java Libraries chapter in the Gradle | |
* User Manual available at https://docs.gradle.org/6.0.1/userguide/java_library_plugin.html | |
*/ | |
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 PropertiesReader : DefaultTask() { | |
@get:InputFile | |
val inputFile: Property<RegularFile> = project.objects.fileProperty() | |
@get:Input | |
val property: Property<String> = project.objects.property<String>().convention("someProperty") | |
@TaskAction | |
fun printProperty() { | |
Properties().run { | |
load(inputFile.get().asFile.inputStream()) | |
println(get(property.get())) | |
} | |
} | |
} | |
val writeProperties by tasks.registering(PropertiesWriter::class) | |
val readProperties by tasks.registering(PropertiesReader::class) { | |
inputFile.set(writeProperties.map { writeProperties.get().outputFile.get() }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment