diff --git a/build.gradle b/build.gradle index 6907a252..cea70017 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,3 @@ -import org.apache.tools.ant.filters.ReplaceTokens - plugins { id 'java' id 'org.springframework.boot' version '3.1.5' @@ -8,7 +6,7 @@ plugins { id 'org.springdoc.openapi-gradle-plugin' version '1.8.0' id 'org.hidetake.swagger.generator' version '2.19.2' // id 'org.graalvm.buildtools.native' version '0.9.28' - id 'org.ajoberstar.grgit' version '5.2.1' + id 'com.gorylenko.gradle-git-properties' version '2.4.1' } group 'plus.maa' @@ -131,18 +129,7 @@ rootProject.afterEvaluate(){ } } -// 配置资源文件拷贝任务 -processResources { - // 获取当前 commit - def commit = grgit?.head() - // 替换配置文件中的占位符 - filesMatching(['**/*.properties', '**/*.yml', '**/*.yaml']) { file -> - { - file.filter(ReplaceTokens, tokens: [ - // commit 不存在时,填充空字符串 - 'commitAbbreviatedId': commit?.abbreviatedId ?: '', - 'commitDateTime' : commit?.dateTime?.toString() ?: '' - ]) - } - } +gitProperties { + failOnNoGitDirectory = false + keys = ["git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time"] } diff --git a/src/main/java/plus/maa/backend/config/external/Commit.java b/src/main/java/plus/maa/backend/config/external/Commit.java deleted file mode 100644 index 7f0a24a0..00000000 --- a/src/main/java/plus/maa/backend/config/external/Commit.java +++ /dev/null @@ -1,11 +0,0 @@ -package plus.maa.backend.config.external; - -import lombok.Data; - -import java.time.ZonedDateTime; - -@Data -public class Commit { - private String abbreviatedId; - private ZonedDateTime dateTime; -} diff --git a/src/main/java/plus/maa/backend/config/external/Info.java b/src/main/java/plus/maa/backend/config/external/Info.java index 92b20132..eca8e46e 100644 --- a/src/main/java/plus/maa/backend/config/external/Info.java +++ b/src/main/java/plus/maa/backend/config/external/Info.java @@ -1,7 +1,5 @@ package plus.maa.backend.config.external; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - @lombok.Data public class Info { private String title; @@ -9,6 +7,4 @@ public class Info { private String version; private String domain; private String frontendDomain; - @NestedConfigurationProperty - private Commit commit; } \ No newline at end of file diff --git a/src/main/java/plus/maa/backend/controller/SystemController.java b/src/main/java/plus/maa/backend/controller/SystemController.java index d4243dc8..b906d8cb 100644 --- a/src/main/java/plus/maa/backend/controller/SystemController.java +++ b/src/main/java/plus/maa/backend/controller/SystemController.java @@ -4,6 +4,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.boot.info.GitProperties; +import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -20,7 +22,10 @@ @RestController @RequiredArgsConstructor public class SystemController { + private final MaaCopilotProperties properties; + @Nullable // 非必须字段,当 Git 仓库不存在时为 null + private final GitProperties gitProperties; @GetMapping("/") @Operation(summary = "Tests if the server is ready.") @@ -38,7 +43,7 @@ public MaaResult getSystemVersion() { systemInfo.setTitle(info.getTitle()); systemInfo.setDescription(info.getDescription()); systemInfo.setVersion(info.getVersion()); - systemInfo.setCommit(info.getCommit()); + systemInfo.setGit(gitProperties); return MaaResult.success(systemInfo); } diff --git a/src/main/java/plus/maa/backend/controller/response/MaaSystemInfo.java b/src/main/java/plus/maa/backend/controller/response/MaaSystemInfo.java index c3496ba8..51558746 100644 --- a/src/main/java/plus/maa/backend/controller/response/MaaSystemInfo.java +++ b/src/main/java/plus/maa/backend/controller/response/MaaSystemInfo.java @@ -1,7 +1,7 @@ package plus.maa.backend.controller.response; import lombok.Data; -import plus.maa.backend.config.external.Commit; +import org.springframework.boot.info.GitProperties; /** * @author AnselYuki @@ -11,5 +11,5 @@ public class MaaSystemInfo { private String title; private String description; private String version; - private Commit commit; + private GitProperties git; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 466d3e7d..db6bfe52 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -41,10 +41,3 @@ logging: rollingpolicy: max-history: 14 clean-history-on-start: true - -maa-copilot: - info: - # 这几个参数应在编译时生成,不宜修改 - commit: - abbreviated-id: @commitAbbreviatedId@ - date-time: @commitDateTime@ \ No newline at end of file