Use git commit sha and rev to specify mod version
This commit is contained in:
parent
a0a21eb575
commit
2b7ef90154
@ -1,17 +1,17 @@
|
|||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import groovy.util.Node
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import groovy.util.NodeList
|
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||||
import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo
|
|
||||||
|
|
||||||
val mod_version: String by project
|
val mod_version: String by project
|
||||||
val mc_version: String by project
|
val mc_version: String by project
|
||||||
val forge_version: String by project
|
val forge_version: String by project
|
||||||
val mod_id: String by project
|
val mod_id: String by project
|
||||||
val handle_deps: String by project
|
val handle_deps: String by project
|
||||||
|
val use_commit_hash_in_version: String by project
|
||||||
val handleDeps = handle_deps == "true"
|
val handleDeps = handle_deps == "true"
|
||||||
|
val useCommitHashInVersion = use_commit_hash_in_version == "true"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
@ -26,9 +26,62 @@ configurations {
|
|||||||
get("implementation").extendsFrom(get("library"), get("klibrary"))
|
get("implementation").extendsFrom(get("library"), get("klibrary"))
|
||||||
}
|
}
|
||||||
|
|
||||||
version = mod_version
|
version = if (useCommitHashInVersion) getCommitVersion() else mod_version
|
||||||
group = "ru.dbotthepony"
|
group = "ru.dbotthepony"
|
||||||
|
|
||||||
|
fun getCommitVersion(): String {
|
||||||
|
try {
|
||||||
|
val versionStream = FastByteArrayOutputStream()
|
||||||
|
val tagStream = FastByteArrayOutputStream()
|
||||||
|
val countStream = FastByteArrayOutputStream()
|
||||||
|
|
||||||
|
val gotVersion = exec {
|
||||||
|
commandLine("git", "rev-parse", "--short", "HEAD")
|
||||||
|
workingDir(".")
|
||||||
|
standardOutput = versionStream
|
||||||
|
}.exitValue == 0
|
||||||
|
|
||||||
|
val gotCount = exec {
|
||||||
|
commandLine("git", "rev-list", "--count", "HEAD")
|
||||||
|
workingDir(".")
|
||||||
|
standardOutput = countStream
|
||||||
|
}.exitValue == 0
|
||||||
|
|
||||||
|
val gotTag = exec {
|
||||||
|
commandLine("git", "tag", "--points-at", "HEAD")
|
||||||
|
workingDir(".")
|
||||||
|
standardOutput = tagStream
|
||||||
|
}.exitValue == 0
|
||||||
|
|
||||||
|
val version = versionStream.array.copyOfRange(0, versionStream.length).toString(Charsets.UTF_8).trim()
|
||||||
|
val tag = tagStream.array.copyOfRange(0, tagStream.length).toString(Charsets.UTF_8).trim()
|
||||||
|
val count = countStream.array.copyOfRange(0, countStream.length).toString(Charsets.UTF_8).trim()
|
||||||
|
|
||||||
|
if (!gotVersion) {
|
||||||
|
return mod_version
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gotTag && tag != "") {
|
||||||
|
if (gotCount && count != "") {
|
||||||
|
return "$tag-SNAPSHOT-${version}_$count"
|
||||||
|
} else {
|
||||||
|
return "$tag-SNAPSHOT-$version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gotCount && count != "") {
|
||||||
|
return "$mod_version-SNAPSHOT-${version}_$count"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "$mod_version-SNAPSHOT-$version"
|
||||||
|
} catch(err: Throwable) {
|
||||||
|
println("Error getting git version")
|
||||||
|
println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mod_version
|
||||||
|
}
|
||||||
|
|
||||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
println("Targeting Java ${java.toolchain.languageVersion.get()}")
|
println("Targeting Java ${java.toolchain.languageVersion.get()}")
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ org.gradle.daemon=true
|
|||||||
kotlin.stdlib.default.dependency=false
|
kotlin.stdlib.default.dependency=false
|
||||||
|
|
||||||
mod_id=overdrive_that_matters
|
mod_id=overdrive_that_matters
|
||||||
mod_version=1.0-SNAPSHOT
|
mod_version=1.0
|
||||||
|
|
||||||
|
use_commit_hash_in_version=true
|
||||||
|
|
||||||
mc_version=1.19.2
|
mc_version=1.19.2
|
||||||
forge_gradle_version=5.1.27
|
forge_gradle_version=5.1.27
|
||||||
|
Loading…
Reference in New Issue
Block a user