* generate build time property in gradle file

This commit is contained in:
lukas-heiligenbrunner 2019-12-11 13:17:55 +01:00
parent 73d6c86fe3
commit 97214d786e
2 changed files with 4 additions and 11 deletions

View File

@ -1,3 +1,5 @@
import java.text.SimpleDateFormat
plugins {
id 'java'
}
@ -39,6 +41,7 @@ task createProperties(dependsOn: processResources) {
new File("$projectDir/src/resources/version.properties").withWriter { w ->
Properties p = new Properties()
p['version'] = project.version.toString()
p['buildtime'] = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date())
p.store w, null
}
}

View File

@ -1,11 +1,8 @@
package com.wasteinformationserver.basicutils;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class Info {
@ -16,20 +13,13 @@ public class Info {
public static void init(){
Properties prop = new Properties();
try {
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
URL url = Info.class.getResource("/version.properties");
String builddatee = format.format(new Date(new File(url.toURI()).lastModified()));
builddate=builddatee;
prop.load(url.openStream());
version=(String)prop.get("version");
builddate=(String)prop.get("buildtime");
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}