Skip to content

Commit 7a7a2bb

Browse files
committed
Added autoversioning to gradle build
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 1f33d2c commit 7a7a2bb

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

build.gradle

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ plugins {
1616
id 'eclipse'
1717
id 'application'
1818
id 'org.graalvm.buildtools.native' version '0.9.28'
19-
id 'net.researchgate.release' version '3.0.2'
20-
}
21-
22-
release {
23-
git {
24-
requireBranch.set('') // This removes the branch requirement
25-
}
2619
}
2720

2821
repositories {
@@ -212,4 +205,48 @@ task createRelease {
212205

213206
}
214207

208+
tasks.register('bumpVersion') {
209+
description = 'Bumps the version number (patch, minor, or major)'
210+
group = 'Versioning'
211+
212+
doLast {
213+
def versionFile = file('gradle.properties')
214+
def versionFileText = versionFile.text
215+
def versionPattern = /version\s*=\s*(\d+)\.(\d+)\.(\d+)/
216+
def matcher = (versionFileText =~ versionPattern)
217+
218+
if (matcher.find()) {
219+
def major = matcher.group(1) as int
220+
def minor = matcher.group(2) as int
221+
def patch = matcher.group(3) as int
222+
223+
def bumpType = project.hasProperty('bumpType') ? project.bumpType : 'patch'
224+
225+
switch (bumpType) {
226+
case 'major':
227+
major++
228+
minor = 0
229+
patch = 0
230+
break
231+
case 'minor':
232+
minor++
233+
patch = 0
234+
break
235+
case 'patch':
236+
default:
237+
patch++
238+
break
239+
}
240+
241+
def newVersion = "${major}.${minor}.${patch}"
242+
def updatedContent = versionFileText.replaceFirst(versionPattern, "version=$newVersion")
243+
versionFile.text = updatedContent
244+
245+
println "Version bumped to $newVersion"
246+
} else {
247+
throw new GradleException("Version not found in gradle.properties")
248+
}
249+
}
250+
}
251+
215252
nativeCompile.finalizedBy copyNativeExecutable

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.0.0
1+
version=0.1.0

0 commit comments

Comments
 (0)