Files
UniMixins/buildscript/forge-1.7.gradle
T

99 lines
2.3 KiB
Groovy

/** Common code for Forge 1.7.10 builds */
apply plugin: "com.gtnewhorizons.retrofuturagradle"
ext.publishDir = project.multiproject_structure.toBoolean() ? "${projectDir}/../publish" : "${rootDir}/publish"
def runCommand(cmd) {
def commitHashProc = cmd.execute(null, file("${projectDir}"))
commitHashProc.waitFor()
if(commitHashProc.exitValue() == 0){
def commitHash = commitHashProc.text.trim()
return commitHash
} else {
println commitHashProc.err.text
println(cmd + " exited with non-zero return value")
return null
}
}
def getCommitVersion() {
def ver = null
def versionPath = publishDir + "/version.txt"
if(file(versionPath).isFile()) {
ver = file(versionPath).text
} else {
try {
ver = runCommand("git describe --tags --dirty") ?: "UNKNOWN-" + runCommand("git describe --always --dirty") ?: "UNKNOWN"
} catch(Exception e){
println "Failed to run " + cmd + ": " + e.getMessage()
ver = "UNKNOWN"
}
}
ver = ver.trim()
if(ver.charAt(0) == 'v') {
ver = ver.substring(1)
}
return ver
}
project.version = getCommitVersion()
group = project.group
archivesBaseName = "${project.archives_base}-${project.minecraft_version}"
minecraft {
mcVersion.set("1.7.10")
}
processResources {
// This will ensure that this task is redone when the versions or any
// user-defined properties change.
inputs.property "version", version
inputs.property "mcversion", project.minecraft.version
inputs.properties project.ext.getProperties()
filesMatching('*.info') {
expand project.properties
}
}
// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// Add git commit hash to MANIFEST.MF
def getCommitHash(){
try {
def commitHashProc = "git describe --always --dirty".execute()
commitHashProc.waitFor()
if(commitHashProc.exitValue() == 0){
def commitHash = commitHashProc.text.trim()
return commitHash
} else {
println commitHashProc.err.text
throw new Exception("git describe exited with non-zero return value")
}
} catch(Exception e){
println "Failed to get commit version: " + e.getMessage()
}
return "UNKNOWN" // fallback
}
jar {
manifest {
attributes (
'Commit-ID': getCommitHash(),
)
}
}