-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
171 lines (141 loc) · 5.31 KB
/
build.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.gradle.publish.PublishTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
alias(libs.plugins.gradlePluginPublish)
signing
alias(libs.plugins.jetbrains.binaryCompatibilityValidator)
// convention plugin from build-logic
id("io.cloudshiftdev.gradle.conventions")
alias(libs.plugins.release)
}
// define group here to work around inability to apply published version of this plugin to this project
// when the group is defined in 'gradle.properties'
group = "io.cloudshiftdev.gradle"
gradlePlugin {
website.set("https://github.com/cloudshiftinc/gradle-release-plugin")
vcsUrl.set("https://github.com/cloudshiftinc/gradle-release-plugin")
plugins {
create("cloudshiftRelease") {
id = "io.cloudshiftdev.release"
implementationClass = "io.cloudshiftdev.gradle.release.ReleasePlugin"
displayName = "Gradle Release Plugin"
description = project.description
tags.set(listOf("release", "version", "release management"))
}
}
}
release {
preReleaseHooks {
processTemplates {
from(fileTree("docs") { include("**/*.md") })
into(layout.projectDirectory)
propertyFrom(
"compatTestMatrix",
provider {
file(".github/compatibility-test-matrix.json").bufferedReader().use { reader ->
val mapper = jacksonObjectMapper()
mapper.readValue<List<CompatEntry>>(reader).groupBy { it.javaVersion }
.mapValues { entry ->
entry.value.map { GradleVersion.version(it.gradleVersion) }
.sorted().joinToString(", ") { it.version }
}.toSortedMap().entries
}
},
)
}
}
}
data class CompatEntry(val javaVersion: Int, val gradleVersion: String)
dependencies {
implementation(libs.guava)
implementation(libs.semver)
implementation(libs.mustache)
// testing libraries for both unit & compatibility tests
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.engine)
testImplementation(platform(libs.kotest.bom))
testImplementation(libs.kotest.assertions.core)
testImplementation(libs.kotest.assertions.json)
testImplementation(libs.kotest.framework.datatest)
testImplementation(libs.kotest.property)
testImplementation(libs.kotest.runner.junit5)
testImplementation(libs.jetbrains.kotlinx.datetime)
// only for compatibility testing
testImplementation(gradleTestKit())
}
val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
isRequired = !isSnapshot
}
val publishingPredicate = provider {
val ci = System.getenv()["CI"] == "true"
when {
ci -> !isSnapshot
else -> false
}
}
kotlin {
explicitApi()
jvmToolchain { languageVersion.set(JavaLanguageVersion.of(8)) }
}
tasks {
withType<ValidatePlugins>().configureEach {
enableStricterValidation.set(true)
failOnWarning.set(true)
}
named<KotlinCompile>("compileKotlin") {
kotlinOptions {
// language version must be compatible with the earliest supported Gradle version
apiVersion = "1.4"
languageVersion = "1.4"
}
}
withType<PublishToMavenRepository>().configureEach {
onlyIf("Publishing only allowed on CI for non-snapshot releases") { publishingPredicate.get() }
}
withType<PublishTask>().configureEach {
onlyIf("Publishing only allowed on CI for non-snapshot releases") { publishingPredicate.get() }
}
val javaToolchainService = extensions.getByType<JavaToolchainService>()
named<Test>("test") {
systemProperty("compat.gradle.version", GradleVersion.current().version)
}
register<Test>("compatibilityTest") {
javaLauncher.set(
providers.gradleProperty("compatibility-test.java-version").flatMap {
javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(it))
}
},
)
// TODO: remove .get() in Gradle 9, once systemProperty is a MapProperty
systemProperty(
"compat.gradle.version",
providers.gradleProperty("compatibility-test.gradle-version")
.orElse(GradleVersion.current().version).get(),
)
}
register<Test>("compatibilityTestJava8Gradle702") {
javaLauncher.set(
javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
},
)
systemProperty("compat.gradle.version", "7.0.2")
}
register<Test>("compatibilityTestJava20Gradle83") {
javaLauncher.set(
javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(20))
},
)
systemProperty("compat.gradle.version", "8.3")
}
}