Skip to content

Commit 8e52119

Browse files
committed
改用template & 提升 CI 使用的 Java 版本到 25
1 parent c3f69bf commit 8e52119

7 files changed

Lines changed: 45 additions & 49 deletions

File tree

.github/workflows/maven.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v4.2.2
18-
- name: Set up JDK 21
18+
- name: Set up JDK 25
1919
uses: actions/setup-java@v4.7.0
2020
with:
21-
java-version: '21'
21+
java-version: '25'
2222
distribution: 'zulu'
2323

2424
- name: Set variable
2525
id: variables
2626
run: |
27-
echo "PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
27+
echo "version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
2828
29-
- name: Update version
30-
run: mvn versions:set -DnewVersion="${{ steps.variables.outputs.PROJECT_VERSION }}+github#${{ github.run_number }}" -DprocessAllModules=true -DgenerateBackupPoms=false
29+
- name: Update debug build version
30+
run: mvn versions:set -DnewVersion="${{ steps.variables.outputs.version }}+github#${{ github.run_number }}" -DprocessAllModules=true -DgenerateBackupPoms=false
3131

3232
- name: Build with Maven
3333
run: mvn -B package --file pom.xml

MiraiMC-Base/pom.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
<version>3.6.2</version>
6161
<configuration>
6262
<minimizeJar>false</minimizeJar>
63-
<relocations>
64-
<relocation>
65-
<pattern>PROJECT.VERSION</pattern>
66-
<shadedPattern>${project.parent.version}</shadedPattern>
67-
</relocation>
68-
</relocations>
6963
<filters>
7064
<filter>
7165
<artifact>*:*</artifact>
@@ -87,6 +81,19 @@
8781
</execution>
8882
</executions>
8983
</plugin>
84+
<plugin>
85+
<groupId>org.codehaus.mojo</groupId>
86+
<artifactId>templating-maven-plugin</artifactId>
87+
<version>1.0.0</version>
88+
<executions>
89+
<execution>
90+
<id>filter-src</id>
91+
<goals>
92+
<goal>filter-sources</goal>
93+
</goals>
94+
</execution>
95+
</executions>
96+
</plugin>
9097
<!--
9198
<plugin>
9299
<groupId>org.jetbrains.kotlin</groupId>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.dreamvoid.universalpluginupdater;
2+
3+
// These constants are replaced before compilation
4+
@SuppressWarnings("ALL")
5+
public class BuildConstants {
6+
public static final String VERSION = "${version}";
7+
public static final String VERSION_CODE = "${versionCode}";
8+
}

MiraiMC-Base/src/main/java/me/dreamvoid/miraimc/internal/Utils.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.Gson;
44
import com.google.gson.JsonObject;
55
import me.dreamvoid.miraimc.api.MiraiMC;
6+
import me.dreamvoid.universalpluginupdater.BuildConstants;
67
import org.jetbrains.annotations.NotNull;
78
import org.jetbrains.annotations.Nullable;
89

@@ -17,8 +18,6 @@
1718
import java.util.logging.Logger;
1819

1920
public final class Utils {
20-
private static final String version = "PROJECT.VERSION";
21-
2221
static {
2322
Logger logger = Logger.getLogger("MiraiMC Preload Checker");
2423
// 此处放置插件自检代码
@@ -127,7 +126,7 @@ public static String get(String url) throws IOException {
127126

128127
connection.setDoInput(true);
129128
connection.setRequestMethod("GET");
130-
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; Java %s)", version, System.getProperty("os.name"), Utils.getJavaVersion()));
129+
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; Java %s)", BuildConstants.VERSION, System.getProperty("os.name"), Utils.getJavaVersion()));
131130
connection.setConnectTimeout(5000);
132131
connection.setReadTimeout(10000);
133132

@@ -156,7 +155,7 @@ public static String post(JsonObject json, String url) throws IOException {
156155

157156
connection.setDoInput(true);
158157
connection.setRequestMethod("POST");
159-
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; Java %s)", version, System.getProperty("os.name"), Utils.getJavaVersion()));
158+
connection.setRequestProperty("User-Agent", String.format("MiraiMC/%s (%s; Java %s)", BuildConstants.VERSION, System.getProperty("os.name"), Utils.getJavaVersion()));
160159
connection.setRequestProperty("Content-Type", "application/json");
161160
connection.setRequestProperty("Authorization", "Basic YWRtaW46");
162161
connection.setConnectTimeout(5000);
@@ -241,10 +240,21 @@ public static int getJavaVersion() {
241240
}
242241

243242
/**
244-
* 获取插件版本
243+
* 获取插件版本名
245244
* @return 版本
246245
*/
247246
public static String getVersion() {
248-
return version;
247+
return BuildConstants.VERSION;
248+
}
249+
250+
/**
251+
* 获取插件版本号
252+
*
253+
* @return 版本号
254+
*/
255+
public static int getVersionCode() {
256+
return Integer.parseInt(BuildConstants.VERSION_CODE);
249257
}
258+
259+
250260
}

MiraiMC-Velocity/pom.xml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646
<version>3.6.2</version>
4747
<configuration>
4848
<minimizeJar>false</minimizeJar>
49-
<relocations>
50-
<relocation>
51-
<pattern>PROJECT.VERSION</pattern>
52-
<shadedPattern>${project.parent.version}</shadedPattern>
53-
</relocation>
54-
</relocations>
5549
<filters>
5650
<filter>
5751
<artifact>*:*</artifact>
@@ -91,31 +85,6 @@
9185
</execution>
9286
</executions>
9387
</plugin>
94-
<plugin>
95-
<groupId>com.google.code.maven-replacer-plugin</groupId>
96-
<artifactId>replacer</artifactId>
97-
<version>1.5.3</version>
98-
<executions>
99-
<execution>
100-
<phase>prepare-package</phase>
101-
<goals>
102-
<goal>replace</goal>
103-
</goals>
104-
</execution>
105-
</executions>
106-
<configuration>
107-
<basedir>${project.build.directory}</basedir>
108-
<includes>
109-
<include>classes/velocity-plugin.json</include>
110-
</includes>
111-
<replacements>
112-
<replacement>
113-
<token>PROJECT\.VERSION\"</token>
114-
<value>${project.parent.version}\"</value>
115-
</replacement>
116-
</replacements>
117-
</configuration>
118-
</plugin>
11988
</plugins>
12089
</build>
12190

MiraiMC-Velocity/src/main/java/me/dreamvoid/miraimc/velocity/VelocityPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import me.dreamvoid.miraimc.interfaces.PluginConfig;
2525
import me.dreamvoid.miraimc.loader.LibraryLoader;
2626
import me.dreamvoid.miraimc.velocity.utils.Metrics;
27+
import me.dreamvoid.universalpluginupdater.BuildConstants;
2728
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2829
import org.slf4j.Logger;
2930

@@ -37,7 +38,7 @@
3738
@Plugin(
3839
id = "miraimc",
3940
name = "MiraiMC",
40-
version = "PROJECT.VERSION",
41+
version = BuildConstants.VERSION,
4142
description = "MiraiBot for Minecraft server",
4243
url = "https://github.com/DreamVoid/MiraiMC",
4344
authors = {"DreamVoid"}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949
<maven.compiler.source>17</maven.compiler.source>
5050
<maven.compiler.target>17</maven.compiler.target>
51+
<versionCode>23</versionCode>
5152
</properties>
5253

5354
<dependencies>

0 commit comments

Comments
 (0)