Auto inject version and git hash

This commit is contained in:
mingjun97 2022-05-18 18:17:24 -07:00
parent 6c1fad2647
commit d0e2544883
3 changed files with 21 additions and 1 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ build
# Ignore lib # Ignore lib
gc-plugin/lib/ gc-plugin/lib/
gc-plugin/src/main/resources/plugin.json

View File

@ -19,6 +19,8 @@ plugins {
sourceCompatibility = 17 sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
def version_tag = "dev-1.1.2"
repositories { repositories {
mavenCentral() mavenCentral()
} }
@ -50,8 +52,24 @@ dependencies {
} }
task injectGitHash {
def gitCommitHash = {
try {
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
} catch (e) {
return "GIT_NOT_FOUND"
}
}
def pluginJson = {
return new File(projectDir, "src/main/resources/plugin.json.tmpl").text.replace("{{VERSION}}", "${version_tag}-${gitCommitHash()}")
}
new File(projectDir, "src/main/resources/plugin.json").text = pluginJson()
}
jar { jar {
jar.baseName = 'mojoconsole' jar.baseName = 'mojoconsole'
destinationDir = file(".") destinationDir = file(".")
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "mojoconsole-plus", "name": "mojoconsole-plus",
"description": "Grasscutter In Game Web Based Console", "description": "Grasscutter In Game Web Based Console",
"version": "dev-1.1.2", "version": "{{VERSION}}",
"mainClass": "com.mojo.consoleplus.ConsolePlus", "mainClass": "com.mojo.consoleplus.ConsolePlus",
"authors": ["mingjun97"] "authors": ["mingjun97"]