-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
build.gradle.kts
343 lines (298 loc) · 9.84 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
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
plugins {
`java-library`
`maven-publish`
signing
alias(libs.plugins.spotless)
alias(libs.plugins.publish)
alias(libs.plugins.release)
alias(libs.plugins.doma.compile)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.kapt)
}
val javaLangVersion: Int = project.properties["javaLangVersion"].toString().toInt()
val testJavaLangVersion: Int = project.properties["testJavaLangVersion"].toString().toInt()
val modularProjects: List<Project> = subprojects.filter { it.name.startsWith("doma-") }
val integrationTestProjects: List<Project> = subprojects.filter { it.name.startsWith("integration-test-") }
val encoding: String by project
val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")
// Retain a reference to rootProject.libs to make the version catalog accessible within allprojects and subprojects.
// See https://github.com/gradle/gradle/issues/16708
val catalog = libs
fun replaceVersionInArtifact(ver: String) {
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """(private static final String VERSION = ")[^"]*(")""",
"replace" to "\\1${ver}\\2",
"encoding" to encoding,
"flags" to "g"
) {
"fileset"("dir" to ".") {
"include"("name" to "**/Artifact.java")
}
}
}
}
fun replaceVersionInDocs(ver: String) {
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """("org.seasar.doma:doma-(core|kotlin|processor|slf4j|template)?:)[^"]*(")""",
"replace" to "\\1${ver}\\3",
"encoding" to encoding,
"flags" to "g"
) {
"fileset"("dir" to ".") {
"include"("name" to "README.md")
"include"("name" to "docs/**/*.rst")
}
}
}
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """(<doma.version>)[^<]*(</doma.version>)""",
"replace" to "\\1${ver}\\2",
"encoding" to encoding,
"flags" to "g"
) {
"fileset"("dir" to ".") {
"include"("name" to "README.md")
}
}
}
}
allprojects {
apply(plugin = "base")
apply(plugin = catalog.plugins.spotless.get().pluginId)
repositories {
mavenCentral()
}
spotless {
val targetExclude = "src/test/java/org/seasar/aptina/unit/*.java"
val licenseHeaderFile = rootProject.file("spotless/copyright.java")
lineEndings = com.diffplug.spotless.LineEnding.UNIX
java {
targetExclude(targetExclude)
googleJavaFormat(catalog.google.java.format.get().version)
licenseHeaderFile(licenseHeaderFile)
}
// https://github.com/diffplug/spotless/issues/532
format("javaMisc") {
targetExclude(targetExclude)
target("src/**/package-info.java", "src/**/module-info.java")
licenseHeaderFile(licenseHeaderFile, "(package|module|\\/\\*\\*)")
}
kotlin {
ktlint(catalog.ktlint.get().version)
licenseHeaderFile(licenseHeaderFile)
}
kotlinGradle {
ktlint(catalog.ktlint.get().version)
}
format("misc") {
target("**/*.gitignore", "docs/**/*.rst", "**/*.md")
targetExclude("**/bin/**", "**/build/**")
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks {
build {
dependsOn(spotlessApply)
}
}
}
subprojects {
apply(plugin = "java")
dependencies {
testImplementation(catalog.junit.jupiter.api)
testRuntimeOnly(catalog.junit.jupiter.engine)
testRuntimeOnly(catalog.apiguardian)
}
}
configure(modularProjects) {
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "signing")
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(javaLangVersion))
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
val projectUrl: String by project
name.set(project.name)
description.set("DAO Oriented Database Mapping Framework for Java")
url.set(projectUrl)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("nakamura-to")
name.set("Toshihiro Nakamura")
email.set("[email protected]")
}
}
scm {
val githubUrl: String by project
connection.set("scm:git:$githubUrl")
developerConnection.set("scm:git:$githubUrl")
url.set(projectUrl)
}
}
}
}
}
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
val publishing = extensions.getByType(PublishingExtension::class)
sign(publishing.publications)
isRequired = isReleaseVersion
}
tasks {
val replaceVersionInJava by registering {
doLast {
replaceVersionInArtifact(version.toString())
}
}
compileJava {
dependsOn(replaceVersionInJava)
options.encoding = encoding
}
jar {
manifest {
attributes(mapOf("Implementation-Title" to project.name, "Implementation-Version" to archiveVersion))
}
}
javadoc {
options.encoding = encoding
(options as StandardJavadocDocletOptions).apply {
charSet = encoding
docEncoding = encoding
use()
addStringOption("Xdoclint:none", "-quiet")
}
}
compileTestJava {
options.encoding = encoding
options.compilerArgs = listOf("-proc:none")
}
test {
maxHeapSize = "1g"
useJUnitPlatform()
}
build {
dependsOn("publishToMavenLocal")
}
withType<Sign>().configureEach {
onlyIf { isReleaseVersion }
}
}
}
configure(integrationTestProjects) {
apply(plugin = "java")
apply(plugin = catalog.plugins.doma.compile.get().pluginId)
dependencies {
testImplementation(platform(catalog.testcontainers.bom))
testRuntimeOnly(catalog.jdbc.h2)
testRuntimeOnly(catalog.jdbc.mysql)
testRuntimeOnly(catalog.jdbc.oracle)
testRuntimeOnly(catalog.jdbc.postgresql)
testRuntimeOnly(catalog.jdbc.sqlite)
testRuntimeOnly(catalog.jdbc.sqlserver)
testRuntimeOnly(catalog.testcontainers.mysql)
testRuntimeOnly(catalog.testcontainers.oracle)
testRuntimeOnly(catalog.testcontainers.postgresql)
testRuntimeOnly(catalog.testcontainers.sqlserver)
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(testJavaLangVersion))
}
tasks {
withType<JavaCompile> {
options.encoding = encoding
}
compileTestJava {
options.compilerArgs.addAll(listOf("-proc:none"))
}
fun Test.prepare(driver: String) {
val urlKey = "$driver.url"
val url = project.property(urlKey) ?: throw GradleException("The $urlKey property is not found.")
this.systemProperty("driver", driver)
this.systemProperty("url", url)
maxHeapSize = "1g"
useJUnitPlatform()
}
test {
val driver: Any by project
prepare(driver.toString())
}
val h2 by registering(Test::class) {
prepare("h2")
}
val mysql by registering(Test::class) {
prepare("mysql")
}
val mysql8 by registering(Test::class) {
prepare("mysql8")
}
val oracle by registering(Test::class) {
prepare("oracle")
}
val postgresql by registering(Test::class) {
prepare("postgresql")
}
val sqlite by registering(Test::class) {
prepare("sqlite")
}
val sqlserver by registering(Test::class) {
prepare("sqlserver")
}
register("testAll") {
dependsOn(h2, mysql, oracle, postgresql, sqlserver)
}
}
}
rootProject.apply {
release {
newVersionCommitMessage.set("[Gradle Release Plugin] - [skip ci] new version commit: ")
git {
requireBranch.set("master")
}
}
nexusPublishing {
repositories {
sonatype()
}
packageGroup.set("org.seasar")
}
tasks {
val replaceVersion by registering {
doLast {
val releaseVersion = project.properties["release.releaseVersion"]?.toString()
checkNotNull(releaseVersion)
replaceVersionInArtifact(releaseVersion)
replaceVersionInDocs(releaseVersion)
}
}
beforeReleaseBuild {
dependsOn(replaceVersion)
}
updateVersion {
doLast {
val newVersion = project.properties["version"]?.toString()
checkNotNull(newVersion)
replaceVersionInArtifact(newVersion)
}
}
}
}