This Gradle plugin creates tasks that fill templates. The plugin uses the SimpleTemplateEngine.
Edit build.gradle file to apply the plugin:
plugins {
id 'io.github.rkotkiewicz.template' version '1.0.0'
}
Configure the plugin by adding template
section in build.gradle
:
template {
// use `create` to add task
// you can create many tasks
create("templateName") {
// 'from': File | Directory
// mandatory
from.set(file("$projectDir/templates"))
// 'into': Directory
// optional
// default = "$buildDir/taskNamePrefix"
into.set(file("$buildDir/outputDir"))
// binding is map: String -> Any
// optional, but you want to set it
binding([b0: "value0", b1: [1, 2, 42]])
}
}
The configuration will create task with name: fillTemplateNameTemplate
.
The b0: "value0", b1: [1, 2, 42]
bindings will be applied to all template files from "$projectDir/templates"
.
Result will be saved into "$buildDir/outputDir"
.
The template file is in:
$projectDir/src/file.txt
with content:
pi = $pi
template {
create("pi") {
from.set(file("$projectDir/src/file.txt"))
binding([pi: 3.14159265359])
}
}
To generate template run task:
./gradlew fillPiTemplate
The result with content:
pi = 3.14159265359
will be saved into "$buildDir/template/pi/file.txt"
.