-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.gradle.kts
106 lines (93 loc) · 2.79 KB
/
settings.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// SPDX-FileCopyrightText: © 2024 JetBrains s.r.o.
// SPDX-License-Identifier: Apache-2.0
@file:Suppress("UnstableApiUsage")
rootProject.name = "gradle-datalyzer"
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
mavenCentral()
maven("https://repo.gradle.org/gradle/libs-releases") {
name = "GradleLibs"
}
}
}
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
//region git versioning
val gitDescribe: Provider<String> =
providers
.exec {
workingDir(rootDir)
commandLine(
"git",
"describe",
"--always",
"--tags",
"--dirty=-DIRTY",
"--broken=-BROKEN",
"--match=v[0-9]*\\.[0-9]*\\.[0-9]*",
)
isIgnoreExitValue = true
}.standardOutput.asText.map { it.trim() }
val currentBranchName: Provider<String> =
providers
.exec {
workingDir(rootDir)
commandLine(
"git",
"branch",
"--show-current",
)
isIgnoreExitValue = true
}.standardOutput.asText.map { it.trim() }
val currentCommitHash: Provider<String> =
providers.exec {
workingDir(rootDir)
commandLine(
"git",
"rev-parse",
"--short",
"HEAD",
)
isIgnoreExitValue = true
}.standardOutput.asText.map { it.trim() }
/**
* The standard Gradle way of setting the version, which can be set on the CLI with
*
* ```shell
* ./gradlew -Pversion=1.2.3
* ```
*
* This can be used to override [gitVersion].
*/
val standardVersion: Provider<String> = providers.gradleProperty("version")
/** Match simple SemVer tags. The first group is the `major.minor.patch` digits. */
val semverRegex = Regex("""v((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))""")
val gitVersion: Provider<String> =
gitDescribe.zip(currentBranchName) { described, branch ->
val detached = branch.isNullOrBlank()
if (!detached) {
"$branch-SNAPSHOT"
// control chars and slashes aren't allowed in Maven Versions
.map { c -> if (c.isISOControl() || c == '/' || c == '\\') "_" else c }
.joinToString("")
} else {
val descriptions = described.split("-")
val head = descriptions.singleOrNull() ?: ""
// drop the leading `v`, try to find the `major.minor.patch` digits group
val headVersion = semverRegex.matchEntire(head)?.groupValues?.last()
headVersion
?: currentCommitHash.orNull // fall back to using the git commit hash
?: "unknown" // just in case there's no git repo, e.g. someone downloaded a zip archive
}
}
gradle.allprojects {
extensions.add<Provider<String>>("gitVersion", standardVersion.orElse(gitVersion))
}
//endregion