Skip to content

Commit 5409368

Browse files
committed
allow optionally specifying version via git tag
1 parent 3b97647 commit 5409368

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
4343
checkPropertyExists("modName")
4444
checkPropertyExists("modId")
4545
checkPropertyExists("modGroup")
46-
checkPropertyExists("modVersion")
4746
checkPropertyExists("minecraftVersion") // hard-coding this makes it harder to immediately tell what version a mod is in (even though this only really supports 1.12.2)
4847
checkPropertyExists("apiPackage")
4948
checkPropertyExists("accessTransformersFile")
@@ -53,6 +52,7 @@ checkPropertyExists("coreModClass")
5352
checkPropertyExists("containsMixinsAndOrCoreModOnly")
5453

5554
// Optional properties: we can assume some default behavior if these are missing
55+
propertyDefaultIfUnset("modVersion", "")
5656
propertyDefaultIfUnset("autoUpdateBuildScript", false)
5757
propertyDefaultIfUnset("modArchivesBaseName", project.modId)
5858
propertyDefaultIfUnsetWithEnvVar("developmentEnvironmentUserName", "Developer", "DEV_USERNAME")
@@ -244,6 +244,19 @@ tasks.withType(ScalaCompile).configureEach {
244244

245245
// Configure Minecraft
246246

247+
// Try to gather mod version from git tags if version is not manually specified
248+
if (!modVersion) {
249+
try {
250+
modVersion = gitVersion()
251+
} catch (Exception ignored) {
252+
out.style(Style.Failure).text(
253+
"Mod version could not be determined! Property 'modVersion' is not set, and either git is not installed or no git tags exist.\n" +
254+
"Either specify a mod version in 'gradle.properties', or create at least one tag in git for this project."
255+
)
256+
modVersion = 'NO-GIT-TAG-SET'
257+
}
258+
}
259+
247260
version = modVersion
248261
group = modGroup
249262
archivesBaseName = modArchivesBaseName

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ modId = mymodid
55

66
modGroup = com.myname.mymodid
77

8+
# Version of your mod.
9+
# This field can be left empty if you want your mod's version to be determined by the latest git tag instead.
810
modVersion = 1.0.0
911

1012
# The name of your jar when you produce builds, not including any versioning info

0 commit comments

Comments
 (0)