Search code examples
kotlingradlebuildbuild.gradlegradle-kotlin-dsl

How to replace a token in resource file using Kotlin DSL


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]
    }
}

Solution

  • 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