Make injectGitHash as a task

This commit is contained in:
mingjun97 2022-05-10 23:34:53 -07:00 committed by Melledy
parent 570635ea02
commit 41de6bd229

View File

@ -45,13 +45,6 @@ targetCompatibility = JavaVersion.VERSION_17
group = 'xyz.grasscutters' group = 'xyz.grasscutters'
version = '1.1.1-dev' version = '1.1.1-dev'
def gitCommitHash = {
try {
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
} catch (e) {
return "GIT_NOT_FOUND"
}
}
sourceCompatibility = 17 sourceCompatibility = 17
targetCompatibility = 17 targetCompatibility = 17
@ -122,13 +115,6 @@ jar {
from('src/main/java') { from('src/main/java') {
include '*.xml' include '*.xml'
} }
new File(projectDir, "src/main/java/emu/grasscutter/BuildConfig.java").text = """
package emu.grasscutter;
public class BuildConfig {
public static final String VERSION = \"${version}\";
public static final String GIT_HASH = \"${gitCommitHash()}\";
}
"""
destinationDir = file(".") destinationDir = file(".")
} }
@ -242,6 +228,26 @@ javadoc {
} }
} }
task injectGitHash {
doLast {
def gitCommitHash = {
try {
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
} catch (e) {
return "GIT_NOT_FOUND"
}
}
new File(projectDir, "src/main/java/emu/grasscutter/BuildConfig.java").text = """
package emu.grasscutter;
public class BuildConfig {
public static final String VERSION = \"${version}\";
public static final String GIT_HASH = \"${gitCommitHash()}\";
}
"""
}
}
processResources { processResources {
dependsOn "generateProto" dependsOn "generateProto"
dependsOn "injectGitHash"
} }