diff --git a/.gitignore b/.gitignore
index 6aa49287512956886644f7ee8924b01287e203b7..81007ca3f57820fea636679c437524ebf9f111be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,4 +17,3 @@ PROB_LOGFILE_IS_UNDEFINED
 src/main/resources/build.properties
 config.groovy
 local.*
-Version.java
diff --git a/build.gradle b/build.gradle
index 2cf3b7fb8462911976efb5714dc0d01484593f2c..5a8990386d0ab5ea78d950a8caaba510726924fa 100644
--- a/build.gradle
+++ b/build.gradle
@@ -30,33 +30,19 @@ java {
   withJavadocJar()
 }
 
-jar {
-  manifest {
-    attributes 'Main-Class': mainClassName
+processResources {
+  inputs.property("project.version", project.version)
+  filesMatching("org/sablecc/sablecc/build.properties") {
+    expand(version: project.version)
   }
 }
 
-task writeVersion() {
-
-  doFirst {
-    def buildconstants_class = """
-package org.sablecc.sablecc;
-
-public class Version
-{
-  public static final String VERSION = "${project.version}";
-}
-"""
-    File f = file("src/main/java/org/sablecc/sablecc/Version.java")
-    f.delete()
-    f <<  buildconstants_class
+jar {
+  manifest {
+    attributes 'Main-Class': mainClassName
   }
 }
 
-compileJava {
-  dependsOn = ['writeVersion']
-}
-
 publishing {
   publications {
     mavenJava(MavenPublication) {
diff --git a/src/main/java/org/sablecc/sablecc/Version.java b/src/main/java/org/sablecc/sablecc/Version.java
new file mode 100644
index 0000000000000000000000000000000000000000..2925b777b593d21381569491b14fc40d991cbf42
--- /dev/null
+++ b/src/main/java/org/sablecc/sablecc/Version.java
@@ -0,0 +1,35 @@
+
+package org.sablecc.sablecc;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+public class Version
+{
+  public static final String VERSION;
+  static
+  {
+    final Properties buildProperties = new Properties();
+    final InputStream is = Version.class.getResourceAsStream("build.properties");
+    if(is == null)
+    {
+      throw new IllegalStateException("Build properties not found, this should never happen!");
+    }
+    else
+    {
+      try(final Reader r = new InputStreamReader(is, StandardCharsets.UTF_8))
+      {
+        buildProperties.load(r);
+      }
+      catch(final IOException e)
+      {
+        throw new IllegalStateException("IOException while loading build properties, this should never happen!", e);
+      }
+    }
+    VERSION = buildProperties.getProperty("version");
+  }
+}
diff --git a/src/main/resources/org/sablecc/sablecc/build.properties b/src/main/resources/org/sablecc/sablecc/build.properties
new file mode 100644
index 0000000000000000000000000000000000000000..178150d8adcd72de8d62a2fea7bb8611961d2a38
--- /dev/null
+++ b/src/main/resources/org/sablecc/sablecc/build.properties
@@ -0,0 +1,3 @@
+# The values for these properties are generated during the build.
+# See the configuration of the processResources task in build.gradle.
+version=${version}