Skip to content

Commit

Permalink
allow optionally specifying version via git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Jun 4, 2023
1 parent 3b97647 commit 5409368
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def out = services.get(StyledTextOutputFactory).create('an-output')
checkPropertyExists("modName")
checkPropertyExists("modId")
checkPropertyExists("modGroup")
checkPropertyExists("modVersion")
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)
checkPropertyExists("apiPackage")
checkPropertyExists("accessTransformersFile")
Expand All @@ -53,6 +52,7 @@ checkPropertyExists("coreModClass")
checkPropertyExists("containsMixinsAndOrCoreModOnly")

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

// Configure Minecraft

// Try to gather mod version from git tags if version is not manually specified
if (!modVersion) {
try {
modVersion = gitVersion()
} catch (Exception ignored) {
out.style(Style.Failure).text(
"Mod version could not be determined! Property 'modVersion' is not set, and either git is not installed or no git tags exist.\n" +
"Either specify a mod version in 'gradle.properties', or create at least one tag in git for this project."
)
modVersion = 'NO-GIT-TAG-SET'
}
}

version = modVersion
group = modGroup
archivesBaseName = modArchivesBaseName
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ modId = mymodid

modGroup = com.myname.mymodid

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

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

0 comments on commit 5409368

Please sign in to comment.