-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle.kts
300 lines (256 loc) · 8.75 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
kotlin("jvm") version "1.9.23"
signing
`maven-publish`
id("com.netflix.nebula.release") version "17.2.2"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("com.google.code.gson:gson:2.10.1")
implementation("org.apache.httpcomponents:httpcore:4.4.16")
implementation("org.apache.httpcomponents:httpclient:4.5.14")
compileOnly("io.prometheus:prometheus-metrics-core:1.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.slf4j:slf4j-simple:1.7.36")
}
// Kotlin settings
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.apiVersion = "1.6"
kotlinOptions.languageVersion = "1.6"
}
// Unit tests settings
tasks.withType<Test> {
enableAssertions = true
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.PASSED, TestLogEvent.STARTED, TestLogEvent.FAILED, TestLogEvent.SKIPPED)
showStandardStreams = false
}
}
java {
withSourcesJar()
withJavadocJar()
}
val settingsProvider = SettingsProvider()
tasks {
// All checks were already made by workflow "On pull request" => no checks here
if (gradle.startParameter.taskNames.contains("final")) {
named("build").get().apply {
dependsOn.removeIf { it == "check" }
}
}
afterEvaluate {
// Publish artifacts to Maven Central before pushing new git tag to repo
named("release").get().apply {
dependsOn(named("publishToSonatype").get())
}
named("closeAndReleaseStagingRepository").get().apply {
dependsOn(named("final").get())
}
}
}
tasks.withType<Sign> {
doFirst {
settingsProvider.validateGPGSecrets()
}
dependsOn(tasks.getByName("build"))
}
tasks.withType<PublishToMavenRepository> {
doFirst {
settingsProvider.validateSonatypeCredentials()
}
}
tasks.register("printFinalReleaseNote") {
doLast {
printFinalReleaseNote(
groupId = PublicationSettings.GROUP_ID,
artifactId = PublicationSettings.ARTIFACT_ID,
sanitizedVersion = project.sanitizeVersion()
)
}
dependsOn(tasks.getByName("final"))
}
tasks.register("printDevSnapshotReleaseNote") {
doLast {
printDevSnapshotReleaseNote(
groupId = PublicationSettings.GROUP_ID,
artifactId = PublicationSettings.ARTIFACT_ID,
sanitizedVersion = project.sanitizeVersion()
)
}
dependsOn(tasks.getByName("devSnapshot"))
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
groupId = PublicationSettings.GROUP_ID
artifactId = PublicationSettings.ARTIFACT_ID
version = project.sanitizeVersion()
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
name.set(PublicationSettings.POM_NAME)
description.set(PublicationSettings.POM_DESCRIPTION)
url.set(PublicationSettings.POM_URL)
licenses {
license {
name.set(PublicationSettings.LICENSE_NAME)
url.set(PublicationSettings.LICENSE_URL)
}
}
developers {
developer {
id.set(PublicationSettings.DEVELOPER_ID)
name.set(PublicationSettings.DEVELOPER_NAME)
email.set(PublicationSettings.DEVELOPER_EMAIL)
}
}
scm {
connection.set(PublicationSettings.SCM_CONNECTION)
developerConnection.set(PublicationSettings.SCM_CONNECTION)
url.set(PublicationSettings.SCM_URL)
}
}
}
}
}
signing {
useInMemoryPgpKeys(settingsProvider.gpgSigningKey, settingsProvider.gpgSigningPassword)
sign(publishing.publications["mavenJava"])
}
nexusPublishing {
repositories {
sonatype {
useStaging.set(!project.isSnapshotVersion())
packageGroup.set(PublicationSettings.GROUP_ID)
username.set(settingsProvider.sonatypeUsername)
password.set(settingsProvider.sonatypePassword)
// nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
// snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
// We want to change SNAPSHOT versions format from:
// <major>.<minor>.<patch>-dev.#+<branchname>.<hash> (local branch)
// <major>.<minor>.<patch>-dev.#+<hash> (github pull request)
// to:
// <major>.<minor>.<patch>-dev+<branchname>-SNAPSHOT
fun Project.sanitizeVersion(): String {
val version = version.toString()
return if (project.isSnapshotVersion()) {
val githubHeadRef = settingsProvider.githubHeadRef
if (githubHeadRef != null) {
// github pull request
version
.replace(Regex("-dev\\.\\d+\\+[a-f0-9]+$"), "-dev+$githubHeadRef-SNAPSHOT")
} else {
// local branch
version
.replace(Regex("-dev\\.\\d+\\+"), "-dev+")
.replace(Regex("\\.[a-f0-9]+$"), "-SNAPSHOT")
}
} else {
version
}
}
fun Project.isSnapshotVersion() = version.toString().contains("-dev.")
fun printFinalReleaseNote(groupId: String, artifactId: String, sanitizedVersion: String) {
println()
println("========================================================")
println()
println("New RELEASE artifact version were published:")
println(" groupId: $groupId")
println(" artifactId: $artifactId")
println(" version: $sanitizedVersion")
println()
println("Discover on Maven Central:")
println(" https://repo1.maven.org/maven2/${groupId.replace('.', '/')}/$artifactId/")
println()
println("Edit or delete artifacts on OSS Nexus Repository Manager:")
println(" https://oss.sonatype.org/#nexus-search;gav~$groupId~~~~")
println()
println("Control staging repositories on OSS Nexus Repository Manager:")
println(" https://oss.sonatype.org/#stagingRepositories")
println()
println("========================================================")
println()
}
fun printDevSnapshotReleaseNote(groupId: String, artifactId: String, sanitizedVersion: String) {
println()
println("========================================================")
println()
println("New developer SNAPSHOT artifact version were published:")
println(" groupId: $groupId")
println(" artifactId: $artifactId")
println(" version: $sanitizedVersion")
println()
println("Discover on Maven Central:")
println(" https://oss.sonatype.org/content/repositories/snapshots/${groupId.replace('.', '/')}/$artifactId/")
println()
println("Edit or delete artifacts on OSS Nexus Repository Manager:")
println(" https://oss.sonatype.org/#nexus-search;gav~$groupId~~~~")
println()
println("========================================================")
println()
}
class SettingsProvider {
val gpgSigningKey: String?
get() = System.getenv(GPG_SIGNING_KEY_PROPERTY)
val gpgSigningPassword: String?
get() = System.getenv(GPG_SIGNING_PASSWORD_PROPERTY)
val sonatypeUsername: String?
get() = System.getenv(SONATYPE_USERNAME_PROPERTY)
val sonatypePassword: String?
get() = System.getenv(SONATYPE_PASSWORD_PROPERTY)
val githubHeadRef: String?
get() = System.getenv(GITHUB_HEAD_REF_PROPERTY)
fun validateGPGSecrets() = require(
value = !gpgSigningKey.isNullOrBlank() && !gpgSigningPassword.isNullOrBlank(),
lazyMessage = { "Both $GPG_SIGNING_KEY_PROPERTY and $GPG_SIGNING_PASSWORD_PROPERTY environment variables must not be empty" }
)
fun validateSonatypeCredentials() = require(
value = !sonatypeUsername.isNullOrBlank() && !sonatypePassword.isNullOrBlank(),
lazyMessage = { "Both $SONATYPE_USERNAME_PROPERTY and $SONATYPE_PASSWORD_PROPERTY environment variables must not be empty" }
)
private companion object {
private const val GPG_SIGNING_KEY_PROPERTY = "GPG_SIGNING_KEY"
private const val GPG_SIGNING_PASSWORD_PROPERTY = "GPG_SIGNING_PASSWORD"
private const val SONATYPE_USERNAME_PROPERTY = "SONATYPE_USERNAME"
private const val SONATYPE_PASSWORD_PROPERTY = "SONATYPE_PASSWORD"
private const val GITHUB_HEAD_REF_PROPERTY = "GITHUB_HEAD_REF"
}
}
object PublicationSettings {
const val GROUP_ID = "com.ecwid.clickhouse"
const val ARTIFACT_ID = "clickhouse-client"
const val POM_NAME = "Ecwid ClickHouse Client"
const val POM_DESCRIPTION = "Java client for ClickHouse HTTP API (https://clickhouse.com)"
const val POM_URL = "https://github.com/Ecwid/clickhouse-client"
const val DEVELOPER_ID = "vgv"
const val DEVELOPER_NAME = "Vasily Vasilkov"
const val DEVELOPER_EMAIL = "[email protected]"
const val LICENSE_NAME = "The Apache License, Version 2.0"
const val LICENSE_URL = "https://www.apache.org/licenses/LICENSE-2.0.txt"
const val SCM_CONNECTION = "scm:git:[email protected]:Ecwid/clickhouse-client.git"
const val SCM_URL = "https://github.com/Ecwid/clickhouse-client.git"
const val STAGING_PACKAGE_GROUP = "com.ecwid"
}