Skip to content
Permalink
Browse files

Gradle: Set the version property via GrGit for all projects

A project's version property is an Object, not a String, so we can
dynamically determine the version at build time in toString().

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information...
sschuberth committed Jul 11, 2019
1 parent 61e1615 commit 5e82e014049ea985b4a5a2aa768bed80cff1e97f
Showing with 12 additions and 6 deletions.
  1. +10 −0 build.gradle.kts
  2. +2 −6 model/build.gradle.kts
@@ -4,6 +4,8 @@ import com.here.ort.gradle.*

import io.gitlab.arturbosch.detekt.detekt

import org.ajoberstar.grgit.Grgit

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

@@ -261,6 +263,14 @@ subprojects {
from(dokkaJavadoc.get().outputDirectory)
}

version = object : Object() {
private val git = Grgit.open(mapOf("dir" to rootDir))

override fun toString(): String {
return git.describe(mapOf("longDescr" to true, "tags" to true)) ?: git.head().abbreviatedId
}
}

configure<PublishingExtension> {
publications {
create<MavenPublication>(name) {
@@ -1,7 +1,5 @@
import com.here.ort.gradle.*

import org.ajoberstar.grgit.Grgit

import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

val jacksonVersion: String by project
@@ -34,15 +32,13 @@ val generateVersionResource by tasks.registering {
group = "Build"
description = "Generates a plain text resource file containing the current application version."

val git = Grgit.open(mapOf("dir" to rootDir))
val version = git.describe(mapOf("longDescr" to true, "tags" to true)) ?: git.head().abbreviatedId
val versionFile = file("$projectDir/src/main/resources/VERSION")

inputs.property("version", version)
inputs.property("version", version.toString())
outputs.file(versionFile)

doLast {
versionFile.writeText(version)
versionFile.writeText(version.toString())
}
}

0 comments on commit 5e82e01

Please sign in to comment.
You can’t perform that action at this time.