Commit 1b89315f authored by dgelessus's avatar dgelessus
Browse files

Store version number in properties instead of generating Version class

parent 5a7f44c6
......@@ -17,4 +17,3 @@ PROB_LOGFILE_IS_UNDEFINED
src/main/resources/build.properties
config.groovy
local.*
Version.java
......@@ -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) {
......
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");
}
}
# The values for these properties are generated during the build.
# See the configuration of the processResources task in build.gradle.
version=${version}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment