Skip to content

Commit 4325e59

Browse files
committed
replace gradle-git-versioning with custom implementation (because the plugin doesn't support config cache)
1 parent dcd851e commit 4325e59

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

build.gradle.kts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@ import buildsrc.config.excludeGeneratedGradleDsl
22

33
plugins {
44
idea
5-
id("me.qoomon.git-versioning")
65
id("org.jetbrains.kotlinx.kover")
76
buildsrc.convention.base
87
}
98

109

1110
project.group = "dev.adamko.kxstsgen"
12-
project.version = "0.0.0-SNAPSHOT"
13-
gitVersioning.apply {
14-
refs {
15-
considerTagsOnBranches = true
16-
branch(".+") { version = "\${ref}-SNAPSHOT" }
17-
tag("v(?<version>.*)") { version = "\${ref.version}" }
18-
}
19-
20-
// optional fallback configuration in case of no matching ref configuration
21-
rev { version = "\${commit}" }
11+
project.version = object {
12+
val gitVersion = project.gitVersion
13+
override fun toString(): String = gitVersion.get()
2214
}
2315

2416
idea {
@@ -32,3 +24,12 @@ idea {
3224
)
3325
}
3426
}
27+
28+
val projectVersion by tasks.registering {
29+
description = "prints the project version"
30+
group = "help"
31+
val version = providers.provider { project.version }
32+
doLast {
33+
logger.quiet("${version.orNull}")
34+
}
35+
}

buildSrc/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dependencies {
77

88
implementation(libs.gradlePlugin.kotlin)
99
implementation(libs.gradlePlugin.kotlinSerialization)
10-
implementation(libs.gradlePlugin.gitVersioning)
1110
implementation(libs.gradlePlugin.gradleNode)
1211
implementation(libs.gradlePlugin.kotlinxKover)
1312
implementation(libs.gradlePlugin.kotlinxKnit)

gradle/libs.versions.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
jvmTarget = "11"
44
kotlinTarget = "1.8"
55

6-
kotlin = "1.8.22" # https://github.com/JetBrains/kotlin/releases
6+
kotlin = "1.9.10" # https://github.com/JetBrains/kotlin/releases
77

8-
kotlinSymbolProcessing = "1.9.0-1.0.13" # https://github.com/google/ksp/releases
8+
kotlinSymbolProcessing = "1.9.0-1.0.13" # https://github.com/google/ksp/releases
99
kotlinCompileTesting = "1.5.0" # https://github.com/tschuchortdev/kotlin-compile-testing/releases
1010

1111
kotlinx-serialization = "1.5.1" # https://github.com/Kotlin/kotlinx.serialization/releases/
@@ -22,7 +22,6 @@ kotlinProcess = "1.4.1" # https://github.com/pgreze/kotlin-proc
2222
classgraph = "4.8.162" # https://github.com/classgraph/classgraph/releases
2323

2424
gradleNodePlugin = "4.0.0" # https://github.com/node-gradle/gradle-node-plugin/releases
25-
gitVersioningPlugin = "6.4.2" # https://github.com/qoomon/gradle-git-versioning-plugin/releases
2625

2726
[libraries]
2827

@@ -68,7 +67,6 @@ kotlinx-knit-test = { module = "org.jetbrains.kotlinx:kotlinx-knit-test", versio
6867

6968
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
7069
gradlePlugin-kotlinSerialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
71-
gradlePlugin-gitVersioning = { module = "me.qoomon:gradle-git-versioning-plugin", version.ref = "gitVersioningPlugin" }
7270
gradlePlugin-gradleNode = { module = "com.github.node-gradle:gradle-node-plugin", version.ref = "gradleNodePlugin" }
7371
gradlePlugin-kotlinxKover = { module = "org.jetbrains.kotlinx:kover", version.ref = "kotlinx-kover" }
7472
gradlePlugin-kotlinxKnit = { module = "org.jetbrains.kotlinx:kotlinx-knit", version.ref = "kotlinx-knit" }

settings.gradle.kts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UnstableApiUsage")
2+
13
rootProject.name = "kotlinx-serialization-typescript-generator"
24

35
pluginManagement {
@@ -7,7 +9,6 @@ pluginManagement {
79
}
810
}
911

10-
@Suppress("UnstableApiUsage")
1112
dependencyResolutionManagement {
1213
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
1314

@@ -53,3 +54,65 @@ include(
5354

5455
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
5556
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
57+
58+
//region git versioning
59+
val gitDescribe: Provider<String> =
60+
providers
61+
.exec {
62+
workingDir(rootDir)
63+
commandLine(
64+
"git",
65+
"describe",
66+
"--always",
67+
"--tags",
68+
"--dirty=-SNAPSHOT",
69+
"--broken=-SNAPSHOT",
70+
"--match=v[0-9]*\\.[0-9]*\\.[0-9]*",
71+
)
72+
isIgnoreExitValue = true
73+
}.standardOutput.asText.map { it.trim() }
74+
75+
val currentBranchName: Provider<String> =
76+
providers
77+
.exec {
78+
workingDir(rootDir)
79+
commandLine(
80+
"git",
81+
"branch",
82+
"--show-current",
83+
)
84+
isIgnoreExitValue = true
85+
}.standardOutput.asText.map { it.trim() }
86+
87+
val currentCommitHash: Provider<String> =
88+
providers.exec {
89+
workingDir(rootDir)
90+
commandLine(
91+
"git",
92+
"rev-parse",
93+
"--short",
94+
"HEAD",
95+
)
96+
isIgnoreExitValue = true
97+
}.standardOutput.asText.map { it.trim() }
98+
99+
val gitVersion: Provider<String> =
100+
gitDescribe.zip(currentBranchName) { described, branch ->
101+
val snapshot = if ("SNAPSHOT" in described) "-SNAPSHOT" else ""
102+
103+
val descriptions = described.split("-")
104+
105+
if (branch.isNullOrBlank() && descriptions.size in 1..2) {
106+
// detached if there's no current branch, or if 'git described' indicates additional commits
107+
val tag = descriptions.getOrNull(0)
108+
"$tag$snapshot"
109+
} else {
110+
// current commit is attached
111+
"$branch$snapshot"
112+
}
113+
}.orElse(currentCommitHash)
114+
115+
gradle.allprojects {
116+
extensions.add<Provider<String>>("gitVersion", gitVersion)
117+
}
118+
//endregion

0 commit comments

Comments
 (0)