From 0c089af87998ffc4148d7db417502007108beddb Mon Sep 17 00:00:00 2001 From: Thog Date: Mon, 17 Dec 2018 17:01:20 +0100 Subject: Replace all occurences of '@VERSION@' during build --- build.gradle | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e88a3466..28451c7e 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,8 @@ buildscript { } } +import org.apache.tools.ant.filters.ReplaceTokens + apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' @@ -21,6 +23,8 @@ apply plugin: 'maven' group = 'cuchaz' version = '0.12.2' +def filteredSourceDir = file("${buildDir}/filtered") + def ENV = System.getenv() if (ENV.BUILD_NUMBER) { version = version + "." + "${System.getenv().BUILD_NUMBER}" @@ -39,8 +43,24 @@ sourceSets { java { srcDir 'src/test/java' } resources { srcDir 'test' } } + filtered { + java { srcDir filteredSourceDir } + } } +compileJava.source = sourceSets.filtered.java + +task processVersion(type: Copy) { + from sourceSets.main.java + into filteredSourceDir + + filter { String line -> + ("$line".replaceAll('@VERSION@', version)) + } +} + +compileJava.dependsOn processVersion + repositories { mavenLocal() mavenCentral() @@ -169,7 +189,8 @@ task('libJar', type: Jar, dependsOn: classes) { task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' - from sourceSets.main.allSource + from sourceSets.main.resources + from sourceSets.filtered.java } artifacts { -- cgit v1.2.3