-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
368 lines (317 loc) · 12.5 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
368 lines (317 loc) · 12.5 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
* Copyright 2024-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.time.Duration
import net.ltgt.gradle.errorprone.errorprone
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
id("eclipse")
id("idea")
id("java-library")
id("spotless-java-extension")
id("maven-publish")
id("signing")
alias(libs.plugins.errorprone)
alias(libs.plugins.buildconfig)
alias(libs.plugins.nexus.publish)
}
repositories { mavenCentral() }
java {
toolchain { languageVersion = JavaLanguageVersion.of(17) } // Remember to update javadoc links
withJavadocJar()
withSourcesJar()
}
tasks.withType<Javadoc> {
val standardDocletOptions = options as StandardJavadocDocletOptions
standardDocletOptions.apply {
addBooleanOption("Werror", false)
// TODO-HIBERNATE-129 addStringOption("-link-modularity-mismatch", "info")
addBooleanOption("serialwarn", true)
addBooleanOption("Xdoclint:all", true)
addBooleanOption(
"Xdoclint/package:-" +
"com.mongodb.hibernate.internal.*" +
",com.mongodb.hibernate.dialect.*" +
",com.mongodb.hibernate.jdbc.*",
true,
)
addStringOption("-show-module-contents", "api")
addStringOption("-show-packages", "exported")
addStringOption("-show-types", "protected")
author(true)
version(true)
encoding("UTF-8")
charSet("UTF-8")
docEncoding("UTF-8")
addBooleanOption("html5", true)
addBooleanOption("-allow-script-in-comments", true)
links =
listOf(
"https://docs.oracle.com/en/java/javase/17/docs/api/",
"https://jakarta.ee/specifications/persistence/3.1/apidocs/",
"https://docs.hibernate.org/orm/7.4/javadocs/",
"https://mongodb.github.io/mongo-java-driver/5.6/apidocs/bson/",
"https://mongodb.github.io/mongo-java-driver/5.6/apidocs/driver-core/",
"https://mongodb.github.io/mongo-java-driver/5.6/apidocs/driver-sync/",
"https://javadoc.io/doc/org.jspecify/jspecify/1.0.0/",
)
// specify the custom `@mongoCme` `javadoc` block tag
tags("mongoCme:TM:Concurrency, Mutability, Execution\\:")
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Integration Test
// Added `Action` explicitly due to an intellij 2025.2 false positive: https://youtrack.jetbrains.com/issue/KTIJ-34210
sourceSets {
create(
"integrationTest",
Action {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
},
)
}
val integrationTestSourceSet: SourceSet = sourceSets["integrationTest"]
val integrationTestImplementation: Configuration by
configurations.getting { extendsFrom(configurations.implementation.get()) }
val integrationTestRuntimeOnly: Configuration by
configurations.getting { extendsFrom(configurations.runtimeOnly.get()) }
val integrationTestTask =
tasks.register<Test>("integrationTest") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
testClassesDirs = integrationTestSourceSet.output.classesDirs
classpath = integrationTestSourceSet.runtimeClasspath
}
tasks.check { dependsOn(integrationTestTask) }
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) }
}
// https://youtrack.jetbrains.com/issue/IDEA-234382/Gradle-integration-tests-are-not-marked-as-test-sources-resources
idea {
module {
testSources.from(integrationTestSourceSet.allSource.srcDirs)
testResources.from(integrationTestSourceSet.resources.srcDirs)
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Static Analysis
spotless {
java {
importOrder()
removeUnusedImports()
palantirJavaFormat(libs.versions.plugin.palantir.get()).formatJavadoc(true)
formatAnnotations()
// need to add license header manually to package-info.java and module-info.java
// due to the bug: https://github.com/diffplug/spotless/issues/532
licenseHeaderFile(file("spotless.license.java")) // contains '$YEAR' placeholder
targetExclude("build/generated/sources/buildConfig/**/*.java")
}
kotlinGradle {
ktfmt(libs.versions.plugin.ktfmt.get()).configure {
it.setMaxWidth(120)
it.setBlockIndent(4)
}
trimTrailingWhitespace()
leadingTabsToSpaces()
endWithNewline()
}
}
tasks.check { dependsOn(tasks.spotlessApply) }
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(
listOf("-Xlint:all", "-Xlint:-requires-automatic", "-Xlint:-requires-transitive-automatic", "-Werror")
)
when (this) {
tasks.compileJava.get() ->
options.errorprone {
disableWarningsInGeneratedCode = true
// Error Prone does not understand the `@hidden` standard tag.
// It also complains about the `javadoc` tags registered via the `-tag`/`-taglet` options
disable("InvalidBlockTag")
disable("AssignmentExpression")
option("NullAway:AnnotatedPackages", "com.mongodb.hibernate")
error("NullAway")
}
else -> options.errorprone.isEnabled = false
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Build Config
buildConfig {
useJavaOutput()
packageName("com.mongodb.hibernate.internal")
documentation.set(
"Generated by the <a href=\"https://github.com/gmazzo/gradle-buildconfig-plugin\">BuildConfig</a> plugin.\n\n@hidden"
)
buildConfigField("NAME", provider { project.name })
buildConfigField("VERSION", provider { "${project.version}" })
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Dependencies
dependencies {
testImplementation(libs.bundles.test.common)
testImplementation(libs.mockito.junit.jupiter)
testRuntimeOnly(libs.h2)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testCompileOnly(libs.checker.qual)
integrationTestImplementation(libs.bundles.test.common)
integrationTestImplementation(libs.hibernate.testing) {
exclude(group = "org.apache.logging.log4j", module = "log4j-core")
}
integrationTestRuntimeOnly("org.junit.platform:junit-platform-launcher")
api(libs.jspecify)
errorprone(libs.nullaway)
errorprone(libs.google.errorprone.core)
api(libs.hibernate.core)
api(libs.mongo.java.driver.sync)
// We need the `libs.findbugs.jsr` dependency to stop `javadoc` from emitting
// `warning: unknown enum constant When.MAYBE`
// `reason: class file for javax.annotation.meta.When not found`.
compileOnly(libs.findbugs.jsr)
implementation(libs.sl4j.api)
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Publishing
val localBuildRepo: Provider<Directory> = project.layout.buildDirectory.dir("repo")
tasks.named<Delete>("clean") { delete.add(localBuildRepo) }
tasks.withType<GenerateModuleMetadata> { enabled = false }
publishing {
repositories {
// publish to local build dir for testing
// `./gradlew publishMavenPublicationToLocalBuildRepository`
//
// publish to the local Maven cache
// `./gradlew publishToMavenLocal`
maven {
url = uri(localBuildRepo.get())
name = "LocalBuild"
}
}
publications {
create<MavenPublication>("mavenJava") {
groupId = "org.mongodb"
artifactId = "mongodb-hibernate"
from(components["java"])
pom {
name = "MongoDB Extension for Hibernate ORM"
description = "An extension providing MongoDB support to Hibernate ORM"
url = "https://www.mongodb.com/"
licenses {
license {
name = "Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0"
}
}
developers {
developer {
name.set("Various")
organization.set("MongoDB")
}
}
scm {
url.set("https://github.com/mongodb/mongo-hibernate")
connection.set("scm:git:https://github.com/mongodb/mongo-hibernate.git")
developerConnection.set("scm:git:https://github.com/mongodb/mongo-hibernate.git")
}
}
}
}
}
// Artifact signing
signing {
val signingKey: String? = providers.gradleProperty("signingKey").getOrNull()
val signingPassword: String? = providers.gradleProperty("signingPassword").getOrNull()
if (signingKey != null && signingPassword != null) {
logger.info("[${project.displayName}] Signing is enabled")
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["mavenJava"])
} else {
logger.info("[${project.displayName}] No Signing keys found, skipping signing configuration")
}
}
// Publishing to the central sonatype portal currently requires the gradle nexus publishing plugin
// Adds a `publishToSonatype` task
val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")
nexusPublishing {
packageGroup.set("org.mongodb")
repositories {
sonatype {
username.set(nexusUsername)
password.set(nexusPassword)
// central portal URLs
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
}
}
connectTimeout.set(Duration.ofMinutes(5))
clientTimeout.set(Duration.ofMinutes(30))
transitionCheckOptions {
// We have many artifacts and Maven Central can take a long time on its compliance checks.
// Set the timeout for waiting for the repository to close to a comfortable 50 minutes.
maxRetries.set(300)
delayBetween.set(Duration.ofSeconds(10))
}
}
// Gets the git version
val gitVersion: String by lazy {
providers
.exec {
isIgnoreExitValue = true
commandLine("git", "describe", "--tags", "--always", "--dirty")
}
.standardOutput
.asText
.map { it.trim().removePrefix("r") }
.getOrElse("UNKNOWN")
}
// Publish snapshots
tasks.register("publishSnapshots") {
group = "publishing"
description = "Publishes snapshots to Sonatype"
if (version.toString().endsWith("-SNAPSHOT")) {
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
dependsOn(tasks.named("publishToSonatype"))
}
}
// Publish the release
tasks.register("publishArchives") {
group = "publishing"
description = "Publishes a release and uploads to Sonatype / Maven Central"
val currentGitVersion = gitVersion
val gitVersionMatch = currentGitVersion == version
doFirst {
if (!gitVersionMatch) {
val cause =
"""
Version mismatch:
=================
$version != $currentGitVersion
The project version does not match the git tag.
"""
.trimMargin()
throw GradleException(cause)
} else {
println("Publishing: ${project.name} : $currentGitVersion")
}
}
if (gitVersionMatch) {
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
dependsOn(tasks.named("publishToSonatype"))
}
}
// `./gradlew -q printProjectVersion`
tasks.register("printProjectVersion") { doLast { logger.quiet(project.version.toString()) } }