Gradle Kotlin DSL Properties Plugin Example
Quick example of how to use the gradle properties plugin with the Kotlin DSL.
This example uses the copy task along with the filter ReplaceTokens to do the heavy lifting. When using the ReplaceTokens filter the token needs to be surrounded with start and end token marker, in this case the @ character.
build.gradle.kts
plugins {
id("net.saliman.properties").version("1.4.6")
}
repositories {
jcenter()
}
task<Copy>("prepareProperties") {
val filterTokens: Map<String, String> by project
from("$rootDir/target") {
include("test-file.txt")
filter<org.apache.tools.ant.filters.ReplaceTokens>("tokens" to filterTokens)
}
into("$buildDir/target/conf")
}
gradle.properties
SAMPLE=testProperty
test-file.txt
sample.property=@SAMPLE@
The output file is located at $buildDir/target/conf/test-file.txt with contents sample.property=testProperty.