diff --git a/.gitignore b/.gitignore
index 881a611..df3d0f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
/build/
/bin/
.project
+lcoal.properties
# debug dir
/run/
diff --git a/build.gradle b/build.gradle
index 0e2a6aa..d721443 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,16 +1,33 @@
+import java.nio.charset.Charset
+import java.nio.charset.StandardCharsets
+
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.0'
+ id 'com.github.gmazzo.buildconfig' version '3.1.0'
}
-group 'cc.sukazyo'
-version VERSION
-project.ext.archiveBaseName = 'Coeur_Morny_Cono'
-project.ext.artifactId = 'morny-coeur'
-mainClassName = 'cc.sukazyo.cono.morny.ServerMain'
+final String proj_group = 'cc.sukazyo'
+final String proj_package = "${proj_group}.cono.morny"
+final String proj_archive_name = MORNY_ARCHIVE_NAME
+
+final String proj_version_base = VERSION
+final String proj_version_delta = VERSION_DELTA
+final String proj_version_use_delta = Boolean.parseBoolean(VERSION_DELTA)
+final String proj_version = proj_version_base + (proj_version_use_delta ? "-δ${proj_version_delta}" : "")
+final String proj_version_codename = CODENAME
+
+final JavaVersion proj_java = JavaVersion.VERSION_17
+final Charset proj_file_encoding = StandardCharsets.UTF_8
+
+group proj_group
+version proj_version
+project.ext.archiveBaseName = proj_archive_name
+project.ext.artifactId = proj_archive_name
+mainClassName = "${proj_package}.ServerMain"
repositories {
mavenCentral()
@@ -31,47 +48,44 @@ dependencies {
}
-task updateVersionCode {
- ant.replaceregexp(match:'VERSION = ["a-zA-Z0-9.\\-_+@]+;', replace:"VERSION = \"$project.version\";", flags:'g', byline:true) {
- fileset(dir: 'src/main/java/cc/sukazyo/cono/morny', includes: 'GradleProjectConfigures.java')
- }
- ant.replaceregexp(match:'CODENAME = ["a-zA-Z0-9]+;', replace:"CODENAME = \"${CODENAME}\";", flags:'g', byline:true) {
- fileset(dir: 'src/main/java/cc/sukazyo/cono/morny', includes: 'GradleProjectConfigures.java')
- }
- ant.replaceregexp(match:'COMPILE_TIMESTAMP = [0-9]+L;', replace:"COMPILE_TIMESTAMP = ${System.currentTimeMillis()}L;", flags:'g', byline:true) {
- fileset(dir: 'src/main/java/cc/sukazyo/cono/morny', includes: 'GradleProjectConfigures.java')
- }
-}
-
-compileJava.dependsOn updateVersionCode
-
test {
useJUnitPlatform()
}
java {
- sourceCompatibility JavaVersion.VERSION_17
- targetCompatibility JavaVersion.VERSION_17
+ sourceCompatibility proj_java
+ targetCompatibility proj_java
withSourcesJar()
}
tasks.withType(JavaCompile) {
- options.encoding = "UTF-8"
+ options.encoding = proj_file_encoding.name()
}
tasks.withType(Javadoc) {
- options.encoding = 'UTF-8'
- options.docEncoding = 'UTF-8'
- options.charSet = 'UTF-8'
+ options.encoding = proj_file_encoding.name()
+ options.docEncoding = proj_file_encoding.name()
+ options.charSet = proj_file_encoding.name()
}
tasks.test {
useJUnitPlatform()
}
+buildConfig {
+
+ packageName(proj_package)
+
+ buildConfigField('String', 'VERSION', "\"${proj_version}\"")
+ buildConfigField('String', 'VERSION_DELTA', "\"${proj_version_delta}\"")
+ buildConfigField('String', 'CODENAME', "\"${proj_version_codename}\"")
+ buildConfigField('long', 'COMPILE_TIMESTAMP', "${System.currentTimeMillis()}L")
+
+}
+
shadowJar {
archiveBaseName.set("${project.ext.archiveBaseName}")
archiveVersion.set("${project.version}")
diff --git a/gradle.properties b/gradle.properties
index 0684f5b..b65028a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,11 @@
## Core
-VERSION = 1.0.0-alpha1
+MORNY_ARCHIVE_NAME = morny-coeur
+
+VERSION = 1.0.0-alpha2
+
+USE_DELTA = true
+VERSION_DELTA = 11061900
CODENAME = beiping
diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java
deleted file mode 100644
index 459f791..0000000
--- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package cc.sukazyo.cono.morny;
-
-/**
- * the final field that will be updated by gradle automatically.
- */
-public class GradleProjectConfigures {
- public static final String VERSION = "1.0.0-alpha1";
- public static final String CODENAME = "beiping";
- public static final long COMPILE_TIMESTAMP = 1667581079623L;
-}
diff --git a/src/main/java/cc/sukazyo/cono/morny/MornySystem.java b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java
index e9a486d..a62290e 100644
--- a/src/main/java/cc/sukazyo/cono/morny/MornySystem.java
+++ b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java
@@ -16,7 +16,7 @@ public class MornySystem {
* 程序的语义化版本号
* 会由 gradle 任务 {@code updateVersionCode} 更新
*/
- public static final String VERSION = GradleProjectConfigures.VERSION;
+ public static final String VERSION = BuildConfig.VERSION;
/**
* Morny Coeur 当前的版本代号.
@@ -26,7 +26,7 @@ public class MornySystem {
*
* 会由 gradle 任务 {@code updateVersionCode} 更新
*/
- public static final String CODENAME = GradleProjectConfigures.CODENAME;
+ public static final String CODENAME = BuildConfig.CODENAME;
/**
* 获取程序 jar 文件的 md5-hash 值
@@ -43,7 +43,6 @@ public class MornySystem {
try {
return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch (IOException | URISyntaxException e) {
- e.printStackTrace(System.out);
return "";
} catch (NoSuchAlgorithmException e) {
e.printStackTrace(System.out);
diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java
index 7e6f6ac..2e330b2 100644
--- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java
+++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java
@@ -192,8 +192,8 @@ public class ServerMain {
%s [UTC]""",
MornySystem.VERSION, MornySystem.CODENAME.toUpperCase(),
MornySystem.getJarMd5(),
- GradleProjectConfigures.COMPILE_TIMESTAMP,
- CommonFormat.formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0)
+ BuildConfig.COMPILE_TIMESTAMP,
+ CommonFormat.formatDate(BuildConfig.COMPILE_TIMESTAMP, 0)
));
return;
@@ -207,7 +207,7 @@ public class ServerMain {
- version %s (%s)(%d)
- Morny %s""",
MornySystem.VERSION,
- MornySystem.getJarMd5(), GradleProjectConfigures.COMPILE_TIMESTAMP,
+ MornySystem.getJarMd5(), BuildConfig.COMPILE_TIMESTAMP,
MornySystem.CODENAME.toUpperCase()
));
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java
index 7b37258..4bbe09c 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java
@@ -1,6 +1,6 @@
package cc.sukazyo.cono.morny.bot.command;
-import cc.sukazyo.cono.morny.GradleProjectConfigures;
+import cc.sukazyo.cono.morny.BuildConfig;
import cc.sukazyo.cono.morny.MornyCoeur;
import cc.sukazyo.cono.morny.MornySystem;
import cc.sukazyo.cono.morny.data.MornyJrrp;
@@ -249,8 +249,8 @@ public class MornyCommands {
escapeHtml(MornySystem.CODENAME.toUpperCase()),
escapeHtml(MornySystem.VERSION),
escapeHtml(MornySystem.getJarMd5()),
- GradleProjectConfigures.COMPILE_TIMESTAMP,
- escapeHtml(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0))
+ BuildConfig.COMPILE_TIMESTAMP,
+ escapeHtml(formatDate(BuildConfig.COMPILE_TIMESTAMP, 0))
)
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
}
@@ -310,8 +310,8 @@ public class MornyCommands {
escapeHtml(MornySystem.VERSION),
escapeHtml(MornySystem.CODENAME),
escapeHtml(MornySystem.getJarMd5()),
- escapeHtml(formatDate(GradleProjectConfigures.COMPILE_TIMESTAMP, 0)),
- GradleProjectConfigures.COMPILE_TIMESTAMP,
+ escapeHtml(formatDate(BuildConfig.COMPILE_TIMESTAMP, 0)),
+ BuildConfig.COMPILE_TIMESTAMP,
// continuous
escapeHtml(formatDuration(System.currentTimeMillis() - MornyCoeur.coeurStartTimestamp)),
System.currentTimeMillis() - MornyCoeur.coeurStartTimestamp,
diff --git a/src/test/java/cc/sukazyo/cono/morny/MornyCLI.java b/src/test/java/cc/sukazyo/cono/morny/MornyCLI.java
index 1b6eea7..c26fca6 100644
--- a/src/test/java/cc/sukazyo/cono/morny/MornyCLI.java
+++ b/src/test/java/cc/sukazyo/cono/morny/MornyCLI.java
@@ -9,7 +9,7 @@ public class MornyCLI {
public static void main (String[] args) {
Scanner line = new Scanner(System.in);
- System.out.print("$ java -jar morny-coeur-"+GradleProjectConfigures.VERSION+".jar " );
+ System.out.print("$ java -jar morny-coeur-"+BuildConfig.VERSION+".jar " );
String x = line.nextLine();
ServerMain.main(UniversalCommand.format(x));