-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
252 lines (226 loc) · 9.2 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
import java.nio.charset.StandardCharsets
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
plugins {
alias(libs.plugins.springboot) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.lombok)
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinPluginSpring)
alias(libs.plugins.kotlinPluginJpa)
alias(libs.plugins.signing)
alias(libs.plugins.projectReport)
alias(libs.plugins.checkstyle)
alias(libs.plugins.pmd)
}
// 安装git hook
tasks.register<Copy>("installGitHooks") {
group = "setup"
description = "Copies git hooks to .git/hooks"
// 源文件路径
val hooksDir = file("${project.rootDir}/.git/hooks")
val sourceDir = file("${project.rootDir}/scripts/git/hooks")
val updateLicenseShell = file("${project.rootDir}/update_license.sh")
// 将文件从源目录拷贝到目标目录
from(sourceDir)
// 目标目录
into(hooksDir)
// 设置执行权限(可选)
doLast {
// 设置 update_license.sh 的执行权限
updateLicenseShell.setExecutable(true)
// 设置 pre-commit 的执行权限
hooksDir.resolve("pre-commit").setExecutable(true)
// 设置 commit-msg 的执行权限
hooksDir.resolve("commit-msg").setExecutable(true)
}
}
val gitHash = providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
}.standardOutput.asText.get().trim()
val suffixes = listOf("-alpha", "-beta", "-snapshot", "-dev", "-test", "-pre")
val now: ZonedDateTime = ZonedDateTime.now(ZoneOffset.UTC)
@Suppress("SpellCheckingInspection")
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssXXX")
val formattedTime: String = now.format(formatter)
fun endsWithAny(input: String, suffixes: List<String>): Boolean {
return suffixes.any { input.endsWith(it, ignoreCase = true) }
}
allprojects {
group = findProperty("group")!! as String
val versionString = findProperty("version")!! as String
version =
if (endsWithAny(
versionString,
suffixes
)
) "$versionString-$gitHash-$formattedTime" else versionString
repositories {
mavenCentral()
maven("https://repo.spring.io/milestone")
}
configurations.configureEach {
resolutionStrategy {
cacheChangingModulesFor(1, TimeUnit.HOURS)
cacheDynamicVersionsFor(1, TimeUnit.HOURS)
}
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
exclude(group = "org.springframework.boot", module = "spring-boot-starter-tomcat")
exclude(group = "ch.qos.logback", module = "logback-classic")
exclude(group = "ch.qos.logback", module = "logback-core")
exclude(group = "pull-parser", module = "pull-parser")
}
}
subprojects {
apply(plugin = rootProject.libs.plugins.java.get().pluginId)
apply(plugin = rootProject.libs.plugins.signing.get().pluginId)
apply(plugin = rootProject.libs.plugins.projectReport.get().pluginId)
apply(plugin = rootProject.libs.plugins.checkstyle.get().pluginId)
apply(plugin = rootProject.libs.plugins.pmd.get().pluginId)
apply(plugin = rootProject.libs.plugins.javaLibrary.get().pluginId)
apply(plugin = rootProject.libs.plugins.idea.get().pluginId)
apply(plugin = rootProject.libs.plugins.lombok.get().pluginId)
apply(plugin = rootProject.libs.plugins.kotlinJvm.get().pluginId)
apply(plugin = rootProject.libs.plugins.kotlinPluginSpring.get().pluginId)
apply(plugin = rootProject.libs.plugins.kotlinPluginJpa.get().pluginId)
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
checkstyle {
toolVersion = "10.20.0"
}
pmd {
isConsoleOutput = true
toolVersion = "7.0.0"
ruleSetFiles = files(
rootProject.file("config/pmd/category/java/errorprone.xml"),
rootProject.file("config/pmd/category/java/bestpractices.xml")
)
}
tasks.withType<Pmd> {
incrementalAnalysis = true
outputs.cacheIf { true }
}
tasks.withType<Checkstyle> {
outputs.cacheIf { true }
}
signing {
val mumuSigningKeyId = "mumu_signing_key_id"
val mumuSigningKey = "mumu_signing_key"
val mumuSigningPassword = "mumu_signing_password"
if (!System.getenv(mumuSigningKeyId).isNullOrBlank() &&
!System.getenv(mumuSigningKey).isNullOrBlank() &&
!System.getenv(mumuSigningPassword).isNullOrBlank()
) {
useInMemoryPgpKeys(
System.getenv(mumuSigningKeyId) as String,
file(System.getenv(mumuSigningKey) as String).readText(),
System.getenv(mumuSigningPassword) as String
)
sign(tasks["jar"])
}
}
tasks.register<Jar>("sourceJar") {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
signing {
sign(tasks.getByName("sourceJar"))
}
artifacts {
add("archives", tasks.named("sourceJar"))
}
tasks.withType<JavaCompile> {
options.encoding = StandardCharsets.UTF_8.name()
}
tasks.named<JavaCompile>("compileJava") {
dependsOn(tasks.named("processResources"))
doFirst {
val hasProcessor = configurations["annotationProcessor"]
.dependencies
.any { it.name.contains("mumu-processor") }
if (hasProcessor) {
options.compilerArgs.addAll(
@Suppress("SpellCheckingInspection")
listOf(
"-Amapstruct.unmappedTargetPolicy=IGNORE",
"-Agradle.version=${gradle.gradleVersion}",
"-Aos.name=${System.getProperty("os.name")}",
"-Ajava.version=${System.getProperty("java.version")}",
"-Aproject.version=${project.version}",
"-Aproject.name=${project.name}",
)
)
} else {
@Suppress("SpellCheckingInspection")
options.compilerArgs.add("-Amapstruct.unmappedTargetPolicy=IGNORE")
}
}
}
tasks.named(
"compileKotlin",
org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask::class.java
) {
compilerOptions {
@Suppress("SpellCheckingInspection")
freeCompilerArgs.add("-Xjsr305=strict")
}
}
tasks.named<Jar>("jar") {
into("META-INF/") {
from(rootProject.file("LICENSE"))
}
manifest {
attributes(
"Implementation-Title" to archiveBaseName.get(),
"Implementation-Version" to archiveVersion.get(),
"Application-Version" to archiveVersion.get(),
"Built-Gradle" to gradle.gradleVersion,
"Build-OS" to System.getProperty("os.name"),
"Build-Jdk" to System.getProperty("java.version"),
"Build-Timestamp" to OffsetDateTime.now(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
)
}
}
dependencies {
implementation(platform(rootProject.libs.spring.boot.dependencies))
annotationProcessor(platform(rootProject.libs.spring.boot.dependencies))
implementation(platform(rootProject.libs.spring.cloud.dependencies))
implementation(platform(rootProject.libs.grpc.bom))
implementation(platform(rootProject.libs.protobuf.bom))
implementation(platform(rootProject.libs.guava.bom))
implementation(rootProject.libs.spring.boot.starter)
implementation(rootProject.libs.spring.boot.starter.log4j2)
implementation(rootProject.libs.spring.boot.starter.validation)
implementation(rootProject.libs.disruptor)
implementation(rootProject.libs.bundles.jackson)
testImplementation(rootProject.libs.bundles.jackson)
implementation(rootProject.libs.jetbrains.annotations)
implementation(rootProject.libs.apiguardian.api)
implementation(rootProject.libs.guava)
implementation(rootProject.libs.commons.lang3)
implementation(rootProject.libs.spring.boot.starter.undertow)
implementation(rootProject.libs.commons.text)
implementation(rootProject.libs.commons.io)
implementation(rootProject.libs.commons.collections4)
implementation(rootProject.libs.jackson.module.kotlin)
implementation(rootProject.libs.kotlin.reflect)
implementation(rootProject.libs.progressbar)
implementation(rootProject.libs.swagger.annotations.jakarta)
implementation(rootProject.libs.moneta)
implementation(rootProject.libs.jackson.datatype.money)
testImplementation(rootProject.libs.junit.jupiter)
annotationProcessor(rootProject.libs.spring.boot.configuration.processor)
implementation(rootProject.libs.mapstruct)
annotationProcessor(rootProject.libs.mapstruct.processor)
testAnnotationProcessor(rootProject.libs.mapstruct.processor)
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
}