Created
November 27, 2021 04:03
-
-
Save DRSchlaubi/e8aa456fd23f60434b054e7ae7ec8e63 to your computer and use it in GitHub Desktop.
Update keys in java files using gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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