Skip to content

Instantly share code, notes, and snippets.

@DRSchlaubi
Created November 27, 2021 04:03
Show Gist options
  • Save DRSchlaubi/e8aa456fd23f60434b054e7ae7ec8e63 to your computer and use it in GitHub Desktop.
Save DRSchlaubi/e8aa456fd23f60434b054e7ae7ec8e63 to your computer and use it in GitHub Desktop.
Update keys in java files using gradle
import org.apache.tools.ant.filters.ReplaceTokens
import java.nio.file.Files
plugins {
java
}
tasks {
val sourcesForRelease = task<Copy>("sourcesForRelease") {
from("src/main/java") {
include("**/Info.java")
val tokens = mapOf("version" to project.version as String)
filter<ReplaceTokens>(mapOf("tokens" to tokens))
}
into("build/filteredSrc")
includeEmptyDirs = false
}
compileJava {
dependsOn(sourcesForRelease)
source(sourcesForRelease.destinationDir)
}
}
sourceSets {
main {
java {
// provided by sourcesForRelease task
exclude("**/Info.java")
}
}
}
public class Info {
public static final String VERSION = "@VERSION@";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment