Skip to content

Commit

Permalink
Add versioning tasks to gradle build
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicasyu committed Oct 18, 2023
1 parent a022a58 commit 37867a8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
68 changes: 66 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id "java"
id "jacoco"
id "com.palantir.git-version" version "3.0.0"
}

version = "3.1.1"
version = "3.1.2"
sourceCompatibility = 1.8

repositories {
Expand All @@ -26,7 +27,7 @@ dependencies {
implementation "fr.irit.smac.thirdparty.edu.gmu.cs:mason:18"
implementation "com.formdev:flatlaf:0.36"
implementation "com.google.code.gson:gson:2.8.6"
runtimeOnly group: 'javax.media', name: 'jmf', version: '2.1.1e'
runtimeOnly group: "javax.media", name: "jmf", version: "2.1.1e"
testImplementation "org.mockito:mockito-core:2.23.+"
testImplementation "org.mockito:mockito-inline:2.23.+"
testImplementation "junit:junit:4.12"
Expand Down Expand Up @@ -63,6 +64,7 @@ jacocoTestReport {
jar {
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
duplicatesStrategy = DuplicatesStrategy.INCLUDE
archiveFileName.set("${project.name}-${gitVersion()}.jar")
manifest {
attributes["Main-Class"] = "arcade.core.gui.GUI"
}
Expand All @@ -71,8 +73,70 @@ jar {
task copyJar(type: Copy) {
from jar
into project.projectDir
doLast {
println "\nBuild the Docker image using:"
println "\ndocker build --build-arg VERSION=${gitVersion()} -t arcade:${gitVersion()} ."
}
}

task showVersion (group: "versioning", description: "Display version information") {
doLast {
def versionFile = file("version.properties")
Properties versionProperties = new Properties()
versionFile.withInputStream { stream -> versionProperties.load(stream) }
println "Version: ${versionProperties.major}.${versionProperties.minor}.${versionProperties.patch}"
println "Full version: ${gitVersion()}"
}
}

task bumpMajor(group: "versioning", description: "Bump to next major version") {
doFirst {
def versionFile = file("version.properties")
ant.propertyfile(file: versionFile) {
entry(key: "major", type: "int", operation: "+", value: 1)
entry(key: "minor", type: "int", operation: "=", value: 0)
entry(key: "patch", type: "int", operation: "=", value: 0)
}
}
}

task bumpMinor(group: "versioning", description: "Bump to next minor version") {
doFirst {
def versionFile = file("version.properties")
ant.propertyfile(file: versionFile) {
entry(key: "major", type: "int", operation: "+", value: 0)
entry(key: "minor", type: "int", operation: "+", value: 1)
entry(key: "patch", type: "int", operation: "=", value: 0)
}
}
}

task bumpPatch(group: "versioning", description: "Bump to next patch version") {
doFirst {
def versionFile = file("version.properties")
ant.propertyfile(file: versionFile) {
entry(key: "major", type: "int", operation: "+", value: 0)
entry(key: "minor", type: "int", operation: "+", value: 0)
entry(key: "patch", type: "int", operation: "+", value: 1)
}
}
}

task updateVersion (group: "versioning", description: "Syncs gradle version with properties") {
doLast {
def versionFile = file("version.properties")
Properties versionProperties = new Properties()
versionFile.withInputStream { stream -> versionProperties.load(stream) }
String newVersion = "${versionProperties.major}.${versionProperties.minor}.${versionProperties.patch}"
buildFile.setText(buildFile.getText().replaceFirst("""version = "$version""", """version = "$newVersion"""))
println "Bumped version to: ${newVersion}"
}
}

build.dependsOn copyJar

test.finalizedBy jacocoTestReport

bumpMajor.finalizedBy updateVersion
bumpMinor.finalizedBy updateVersion
bumpPatch.finalizedBy updateVersion
4 changes: 4 additions & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Wed, 18 Oct 2023 11:37:29 -0400
major=3
minor=1
patch=2

0 comments on commit 37867a8

Please sign in to comment.