What would be the equivament of the following in Kotlin DSL (build.gradle.kts)?
processResources {
from(sourceSets.main.resources.srcDirs) {
filter ReplaceTokens, tokens: [version: version]
}
}
What would be the equivament of the following in Kotlin DSL (build.gradle.kts)?
processResources {
from(sourceSets.main.resources.srcDirs) {
filter ReplaceTokens, tokens: [version: version]
}
}
It's actually super easy:
tasks.processResources {
expand("version" to project.version)
}
And then just put ${version}
in resource and it will be replaced with your project version
As of Gradle 8.4, the you can use a filter. This is useful if you have a large number of tokens to replace
tasks.processResources {
filter<ReplaceTokens>("tokens" to mapOf("version" to project.version))
}
If you have the tokens as a Properties
instance (or an existing Map
), that can be used as well:
val properties: Properties = . . .
tasks.processResources {
filter<ReplaceTokens>("tokens" to properties)
}
© 2022 - 2024 — McMap. All rights reserved.