]> source.dussan.org Git - poi.git/commitdiff
Generate, compile and include class 'org.apache.poi.Version' in Gradle build
authorDominik Stadler <centic@apache.org>
Thu, 16 Sep 2021 19:25:43 +0000 (19:25 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 16 Sep 2021 19:25:43 +0000 (19:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893384 13f79535-47bb-0310-9956-ffa450edef68

poi/build.gradle

index d71e86bc51184c40c492d7d36e6d1ad10d486154..da8eeb9ff1c3a78edc3e74c33e63456032a91724 100644 (file)
@@ -27,6 +27,10 @@ sourceSets {
         if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
             output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
         }
+        java {
+            // also include the generated Version.java
+            srcDirs += 'build/generated-sources'
+        }
     }
     test {
         if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
@@ -55,6 +59,27 @@ dependencies {
     javadocs project(':poi-scratchpad')
 }
 
+// generate and compile the file Version.java file
+task generateVersionJava() {
+    //dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
+
+    File fileIn = file("src/main/version/Version.java.template")
+    File fileOut = file("build/generated-sources/org/apache/poi/Version.java")
+
+    inputs.file fileIn
+    outputs.file fileOut
+
+    doLast {
+        String content = fileIn.text
+
+        content = content.replace("@VERSION@", version)
+        content = content.replace("@DSTAMP@", new Date().format('yyyyMMdd'))
+
+        fileOut.write content
+    }
+}
+compileJava.dependsOn 'generateVersionJava'
+
 final String MODULE_NAME = 'org.apache.poi.poi'
 final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
 final Pattern MODULE_REGEX = ~'\\.jar$'
@@ -177,4 +202,4 @@ publishing {
             }
         }
     }
-}
\ No newline at end of file
+}