Skip to content

Commit

Permalink
Simplify getGitVersion() in build.gradle.kts
Browse files Browse the repository at this point in the history
  • Loading branch information
markwhitaker committed Jul 13, 2024
1 parent 6387ab1 commit eb34619
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import java.io.BufferedReader
import java.io.InputStreamReader

plugins {
`java-library`
}
Expand All @@ -12,23 +9,20 @@ repositories {
}

group = "uk.co.mainwave.mimetypes"
version = getVersionFromGit()
version = getGitVersion()

java.sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
testImplementation("junit:junit:$junitVersion")
}

fun getVersionFromGit(): String {
val processBuilder = ProcessBuilder(listOf("git", "describe", "--tags", "--always"))
fun getGitVersion(): String {
try {
val process = processBuilder.start()
val reader = BufferedReader(InputStreamReader(process.inputStream))
val output = StringBuilder()
output.append(reader.readLine())
val process = ProcessBuilder("git", "describe", "--tags", "--always").start()
val output = process.inputStream.bufferedReader().readLine()
process.waitFor()
return output.toString()
return output
} catch (e: Exception) {
return "1.0.0"
}
Expand Down

0 comments on commit eb34619

Please sign in to comment.