-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
498 lines (441 loc) · 20.2 KB
/
build.gradle.kts
File metadata and controls
498 lines (441 loc) · 20.2 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
import io.github.hylexus.xtream.codec.gradle.utils.XtreamConfig.xtreamConfig
import io.github.hylexus.xtream.codec.gradle.utils.logInfo2
import io.github.hylexus.xtream.codec.gradle.utils.logTip
import net.ltgt.gradle.errorprone.errorprone
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
plugins {
id("java-library")
id("io.spring.dependency-management")
id("maven-publish")
id("io.gitee.pkmer.pkmerboot-central-publisher") apply false
id("signing")
id("checkstyle")
id("net.minecraftforge.licenser") apply false
id("com.github.jk1.dependency-license-report")
id("com.namics.oss.gradle.license-enforce-plugin")
id("net.ltgt.errorprone") apply false
}
val mavenPublications = setOf(
"xtream-codec-base",
"xtream-codec-core",
"xtream-codec-server-reactive",
"jt-808-server-spring-boot-starter-reactive",
"jt-808-server-dashboard-spring-boot-starter-reactive",
)
val errorpronePluginEnabledProjects = setOf(
"xtream-codec-base",
"xtream-codec-core",
"xtream-codec-server-reactive",
"jt-808-server-spring-boot-starter-reactive",
"jt-808-server-dashboard-spring-boot-starter-reactive",
"jt-1078-server-spring-boot-starter-reactive",
"jt-1078-server-dashboard-spring-boot-starter-reactive",
)
version = xtreamConfig.projectVersion
run {
xtreamConfig.javaVersion
xtreamConfig.defaultSpringBootBomVersion
xtreamConfig.defaultSpringCloudBomVersion
xtreamConfig.needSign
}
val mavenRepoConfig = xtreamConfig.mavenRepoConfig
// region Java
configure(subprojects) {
version = xtreamConfig.projectVersion
if (!isJavaProject(project)) {
return@configure
}
logInfo2("configuring project: ${project.name}")
apply(plugin = "java-library")
if (project.errorPronePluginEnabled()) {
apply(plugin = "net.ltgt.errorprone")
}
java {
sourceCompatibility = JavaVersion.toVersion(xtreamConfig.javaVersion)
targetCompatibility = JavaVersion.toVersion(xtreamConfig.javaVersion)
}
tasks.test {
useJUnitPlatform()
// https://github.com/gradle/gradle/issues/7773
// systemProperties(System.getProperties().map { (k, v) -> k.toString() to v }.toMap())
}
tasks.withType<JavaCompile> {
options.compilerArgs.add("-parameters")
options.release.set(xtreamConfig.javaVersion.toInt())
if (project.errorPronePluginEnabled()) {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.github.hylexus.xtream.codec")
option(
"NullAway:ExcludedClasses",
listOf(
"io.github.hylexus.xtream.codec.ext.jt808.builtin.messages",
"io.github.hylexus.xtream.codec.ext.jt808.dashboard.domain.dto",
"io.github.hylexus.xtream.codec.ext.jt808.dashboard.domain.vo",
"io.github.hylexus.xtream.codec.ext.jt1078.dashboard.domain.dto",
"io.github.hylexus.xtream.codec.ext.jt1078.dashboard.domain.vo",
).joinToString(separator = ",")
)
disable(
"MissingSummary",
"StringCaseLocaleUsage",
"StringSplitter",
"UnnecessaryParentheses",
"ImmutableEnumChecker",
"DefaultCharset",
// todo: 有几个注解名和jdk类名冲突 后期考虑提供一个别名?
"JavaLangClash",
"ArrayRecordComponent",
"JavaTimeDefaultTimeZone",
)
}
// Include to disable NullAway on test code
if (name.lowercase(Locale.getDefault()).contains("test")) {
options.errorprone {
disable("NullAway")
disable("IntLiteralCast")
}
}
}
}
apply(plugin = "io.spring.dependency-management")
dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor(0, TimeUnit.SECONDS)
}
applyMavenExclusions(false)
generatedPomCustomization {
enabled(false)
}
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${xtreamConfig.defaultSpringBootBomVersion}")
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${xtreamConfig.defaultSpringCloudBomVersion}")
}
dependencies {
// 其他依赖版本都由上面的 mavenBom 控制
// 这里指定 mavenBom 中没有包含的依赖版本
dependency("io.github.classgraph:classgraph:4.8.174")
dependency("org.bouncycastle:bcprov-jdk18on:1.78.1")
dependency("pro.chenggang:mybatis-r2dbc-spring:3.0.5.RELEASE")
dependency("cn.mybatis-mp:mybatis-mp-spring-boot-starter:1.7.8-spring-boot3")
dependency("cn.mybatis-mp:mybatis-mp-datasource-routing:1.0.2")
dependency("com.clickhouse:clickhouse-jdbc:0.7.2")
dependency("com.clickhouse:clickhouse-client:0.7.1")
dependency("com.clickhouse:clickhouse-r2dbc:0.7.1")
dependency("io.minio:minio:8.5.14")
dependency("com.lmax:disruptor:4.0.0")
dependency("org.jspecify:jspecify:1.0.0")
dependency("org.jetbrains:annotations:26.0.2")
xtreamConfig.thirdpartyDependencies().forEach {
dependency(it.toIdentifier())
}
}
group = "xtream-codec"
version = xtreamConfig.projectVersion
}
dependencies {
// common start
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testCompileOnly("org.projectlombok:lombok")
testAnnotationProcessor("org.projectlombok:lombok")
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
api("org.jspecify:jspecify")
api("org.jetbrains:annotations")
if (project.errorPronePluginEnabled()) {
val errorprone = configurations.getByName("errorprone")
errorprone("com.uber.nullaway:nullaway:0.12.10")
errorprone("com.google.errorprone:error_prone_core:2.42.0")
}
// common end
}
apply(plugin = "checkstyle")
checkstyle {
toolVersion = "10.23.0"
configDirectory.set(rootProject.file("build-script/checkstyle/"))
}
tasks.withType<Checkstyle>().configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(xtreamConfig.javaVersion))
}
}
tasks.withType<Checkstyle> {
// 严重影响构建时间
onlyIf {
val skip = xtreamConfig.skipCheckStyle
if (skip) {
logTip("Disabling task [checkstyle] in project [${project.name}] (xtream.backend.build.checkstyle.enabled == false)")
}
return@onlyIf !skip
}
}
// 本项目开源协议头
if (xtreamConfig.licenseCheckerEnabled) {
apply(plugin = "net.minecraftforge.licenser")
val creationYear = DateTimeFormatter.ofPattern("yyyy").format(LocalDate.now())
configure<net.minecraftforge.licenser.LicenseExtension> {
// setHeader(rootProject.file("build-script/license/license-header"))
header.set(rootProject.resources.text.fromFile("build-script/license/license-header"))
skipExistingHeaders.set(false)
exclude("**/spring.factories")
exclude("**/org.springframework.boot.autoconfigure.AutoConfiguration.imports")
properties {
set("creationYear", creationYear)
}
}
}
apply(plugin = "com.github.jk1.dependency-license-report")
// 第三方依赖 license
licenseReport {
// By default, this plugin will collect the union of all licenses from
// the immediate pom and the parent poms. If your legal team thinks this
// is too liberal, you can restrict collected licenses to only include the
// those found in the immediate pom file
// Defaults to: true
unionParentPomLicenses = true
// Select projects to examine for dependencies.
// Defaults to current project and all its subprojects
// projects = project.subprojects.toTypedArray()
projects = arrayOf(project)
// Don't include artifacts of project's own group into the report
excludeOwnGroup = true
// Don't exclude bom dependencies.
// If set to true, then all boms will be excluded from the report
excludeBoms = true
// excludes = mavenPublications.map { "xtream-codec:$it" }.toTypedArray()
excludes = mavenPublications.flatMap { listOf("xtream-codec:$it", "xtream-codec.ext.jt:$it") }.toTypedArray()
// Set output directory for the report data.
// Defaults to ${project.buildDir}/reports/dependency-license.
outputDir = "${project.layout.projectDirectory}/build/reports/dependency-license"
// Set custom report renderer, implementing ReportRenderer.
// Yes, you can write your own to support any format necessary.
renderers = arrayOf(com.github.jk1.license.render.TextReportRenderer("THIRD-PARTY-NOTICES.txt"))
// This is for the allowed-licenses-file in checkLicense Task
// Accepts File, URL or String path to local or remote file
////// ??? https://github.com/jk1/Gradle-License-Report/issues/252
allowedLicensesFile = rootProject.file("build-script/license/allowed-licenses.json")
}
apply(plugin = "com.namics.oss.gradle.license-enforce-plugin")
tasks.enforceLicenses {
allowedCategories = listOf("Apache", "MIT")
allowedLicenses = listOf("Mulan Permissive Software License, Version 2")
}
}
// endregion Java
// region Maven
configure(subprojects) {
if (!isJavaProject(project)) {
return@configure
}
normalization {
runtimeClasspath {
ignore("META-INF/MANIFEST.MF")
}
}
tasks.jar {
dependsOn("generateLicenseReport")
manifest {
manifest.attributes["Implementation-Title"] = project.name
manifest.attributes["Implementation-Version"] = xtreamConfig.projectVersion
manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.')
manifest.attributes["Created-By"] = "${System.getProperty("java.version")} (${System.getProperty("java.vendor")})"
manifest.attributes["X-Requires-Java-Version"] = xtreamConfig.javaVersion.toInt()
}
from(rootProject.projectDir) {
include("LICENSE")
into("META-INF")
rename("LICENSE", "LICENSE.txt")
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:filtering_files
expand(
"copyright" to LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy")),
"version" to xtreamConfig.projectVersion,
)
}
from(project.projectDir.absolutePath + "/build/reports/dependency-license/") {
include("THIRD-PARTY-NOTICES.txt")
into("META-INF")
rename("THIRD-PARTY-NOTICES.txt", "NOTICE.txt")
}
}
tasks.javadoc {
description = "Generates project-level javadoc for use in -javadoc jar"
options.encoding = "UTF-8"
options.memberLevel = JavadocMemberLevel.PROTECTED
options.header = project.name
options.source = "21"
val docletOptions = options as StandardJavadocDocletOptions
docletOptions.addBooleanOption("html5", true)
docletOptions.version(true)
docletOptions.links("https://docs.oracle.com/en/java/javase/21/docs/api")
docletOptions.charSet("UTF-8")
docletOptions.use(true)
docletOptions.addStringOption("Xdoclint:none", "-quiet")
isFailOnError = false
version = xtreamConfig.projectVersion
logging.captureStandardError(LogLevel.INFO)
logging.captureStandardOutput(LogLevel.INFO)
}
val sourcesJar by tasks.registering(Jar::class) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveClassifier.set("sources")
from(sourceSets.getByName("main").java.srcDirs)
}
val javaDocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.named("javadoc"))
}
apply(plugin = "maven-publish")
val stagingRepositoryPath = xtreamConfig.centralPortalArtifactsTempDir
if (isMavenPublications()) {
if (xtreamConfig.centralPortalMavenRepoEnabled) {
apply(plugin = "io.gitee.pkmer.pkmerboot-central-publisher")
tasks.withType<io.gitee.pkmer.tasks.BundleTask>().configureEach {
dependsOn(tasks.test, tasks.checkstyleTest, tasks.checkstyleMain)
// 只有部分模块有这两个任务
dependsOn(tasks.matching { it.name in setOf("compileJmhJava", "checkstyleJmh") })
}
// 延迟配置,在插件完全应用后再执行
afterEvaluate {
project.extensions.findByType<io.gitee.pkmer.extension.PkmerBootPluginExtension>()?.apply {
sonatypeMavenCentral {
stagingRepository.set(file(stagingRepositoryPath))
username.set(mavenRepoConfig.getProperty("maven-central-portal.username"))
password.set(mavenRepoConfig.getProperty("maven-central-portal.password"))
publishingType.set(io.gitee.pkmer.enums.PublishingType.USER_MANAGED)
}
}
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(sourcesJar)
artifact(javaDocJar)
groupId = xtreamConfig.projectGroupId
artifactId = project.name
version = xtreamConfig.projectVersion
pom {
packaging = "jar"
description.set(project.name)
name.set(project.name)
url.set(xtreamConfig.projectHomePage)
licenses {
license {
name.set(xtreamConfig.projectLicenseName)
url.set(xtreamConfig.projectLicenseUrl)
}
}
developers {
developer {
id.set(xtreamConfig.projectDeveloperId)
name.set(xtreamConfig.projectDeveloperName)
email.set(xtreamConfig.projectDeveloperEmail)
}
}
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
scm {
url.set(xtreamConfig.projectScmUrl)
connection.set(xtreamConfig.projectScmConnection)
developerConnection.set(xtreamConfig.projectScmDeveloperConnection)
}
issueManagement {
system.set(xtreamConfig.projectIssueManagementSystem)
url.set(xtreamConfig.projectIssueManagementUrl)
}
}
repositories {
// 1. 发布到你自己的私有仓库
if (xtreamConfig.privateMavenRepoEnabled) {
maven {
name = "private"
url = uri(mavenRepoConfig.getProperty("privateRepo-release.url"))
credentials {
username = mavenRepoConfig.getProperty("privateRepo-release.username")
password = mavenRepoConfig.getProperty("privateRepo-release.password")
}
}
}
// 2. 发布到 GitHub Packages
if (xtreamConfig.githubMavenRepoEnabled) {
maven {
name = "GitHubPackages"
url = uri(mavenRepoConfig.getProperty("github-pkg.url"))
credentials {
username = System.getenv("GITHUB_ACTOR")
?: System.getProperty("gpr.user")
?: mavenRepoConfig.getProperty("github-pkg.username")
password = System.getenv("GITHUB_TOKEN")
?: System.getProperty("gpr.key")
?: mavenRepoConfig.getProperty("github-pkg.password")
}
}
}
// 3. 发布到 Maven 中央仓库
// 已废弃: 新版中央仓库发版参考 io.gitee.pkmer.pkmerboot-central-publisher
// maven {
// name = "centralPortal"
// url = uri(mavenRepoConfig.getProperty("sonatype-staging.url"))
// credentials {
// username = mavenRepoConfig.getProperty("sonatype-staging.username")
// password = mavenRepoConfig.getProperty("sonatype-staging.password")
// }
// }
maven {
name = "centralPortalLocalArtifacts"
// Specify the local staging repo path in the configuration.
url = uri(stagingRepositoryPath)
}
}
}
}
}
if (xtreamConfig.needSign) {
apply(plugin = "signing")
signing {
// 如果需要签名
// 记得将 build-script/gradle/debug-template.gradle.properties 中的 gpg 配置放到 ~/.gradle/gradle.properties
sign(publishing.publications["maven"])
}
}
}
}
// endregion Maven
fun isJavaProject(project: Project): Boolean {
return project != rootProject
&& (
mavenPublications.contains(project.name)
|| setOf(
"xtream-codec-core-debug",
"xtream-codec-server-reactive-debug-tcp",
"xtream-codec-server-reactive-debug-udp",
"jt-808-server-spring-boot-starter-reactive-debug",
"jt-808-attachment-server-quick-start-blocking",
"jt-808-attachment-server-quick-start-nonblocking",
"jt-808-server-quick-start",
"jt-808-server-quick-start-with-dashboard",
"jt-808-server-quick-start-with-storage-nonblocking",
"jt-808-server-quick-start-with-storage-blocking",
"jt-1078-server-spring-boot-starter-reactive",
"jt-1078-server-dashboard-spring-boot-starter-reactive",
"jt-1078-server-spring-boot-starter-reactive-debug",
"jt-1078-server-quick-start-nonblocking",
"jt-1078-server-quick-start-blocking",
).contains(project.name))
}
fun Project.isMavenPublications(): Boolean {
return mavenPublications.contains(project.name)
}
private fun Project.errorPronePluginEnabled(): Boolean {
return xtreamConfig.errorproneEnabled && project.name in errorpronePluginEnabledProjects
}