|
1 | | -import org.ajoberstar.grgit.Commit |
2 | | -import org.ajoberstar.grgit.Grgit |
| 1 | +import versioning.GitTagValueSource |
| 2 | +import versioning.GitHashValueSource |
3 | 3 |
|
4 | 4 | plugins { |
5 | 5 | kotlin("jvm") |
6 | 6 | `kotlin-dsl` |
7 | | - id("org.ajoberstar.grgit") version "5.3.2" |
8 | 7 | id("com.utopia-rise.maven-central-publish") |
9 | 8 | id("com.gradle.plugin-publish") version "1.2.0" |
10 | 9 | `java-gradle-plugin` |
11 | 10 | } |
12 | 11 |
|
13 | | -val baseVersion = "0.1.4" |
| 12 | +val baseVersion = "0.2.1" |
14 | 13 |
|
15 | | -val grgit = Grgit.open(mapOf("currentDir" to project.rootDir)) |
| 14 | +val exactTag = providers.of(GitTagValueSource::class) { |
| 15 | + parameters.workDir.set(layout.projectDirectory) |
| 16 | +} |
| 17 | + |
| 18 | +val shortHash = providers.of(GitHashValueSource::class) { |
| 19 | + parameters.workDir.set(layout.projectDirectory) |
| 20 | + parameters.abbrev.set(7) |
| 21 | +} |
16 | 22 |
|
17 | | -val currentCommit: Commit = grgit.head() |
18 | | -// check if the current commit is tagged |
19 | | -var tagOnCurrentCommit = grgit.tag.list().firstOrNull { tag -> tag.commit.id == currentCommit.id } |
20 | | -var releaseMode = tagOnCurrentCommit != null |
| 23 | +logger.lifecycle("Current tag is: ${exactTag.orNull}") |
| 24 | +logger.lifecycle("Current commit hash is: ${shortHash.orNull}") |
21 | 25 |
|
22 | | -version = if (!releaseMode) { |
23 | | - "$baseVersion-${currentCommit.abbreviatedId}-SNAPSHOT" |
24 | | -} else { |
25 | | - requireNotNull(tagOnCurrentCommit).name |
| 26 | +val tagValue = exactTag.get() |
| 27 | +version = tagValue.ifBlank { |
| 28 | + "$baseVersion-${shortHash.get()}-SNAPSHOT" |
26 | 29 | } |
27 | 30 |
|
28 | 31 | group = "com.utopia-rise" |
|
0 commit comments