-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
254 lines (220 loc) · 8.43 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
/**
* Copyright (c) 2024 TruthBean(Rogar·Q)
* Debbie is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
buildscript {
repositories {
mavenLocal()
/*maven(url = "http://192.168.1.12:18081/repository/public/") {
isAllowInsecureProtocol = true
}*/
maven("https://mirrors.huaweicloud.com/repository/maven/")
maven("https://plugins.gradle.org/m2/")
maven("https://repo.spring.io/plugins-release/")
}
}
group = "com.truthbean"
allprojects {
repositories {
mavenLocal()
/*maven(url = "http://192.168.1.12:18081/repository/public/") {
isAllowInsecureProtocol = true
}*/
maven("https://mirrors.huaweicloud.com/repository/maven/")
}
}
plugins {
`maven-publish`
signing
idea
eclipse
}
val projectVersion: String by project
// 根据我们在gradle.properties中声明的版本名称,来分辨是release版本还是snapshots版本
val isReleaseBuild = projectVersion.endsWith("RELEASE")
// 声明变量记录maven库地址,判断是发布到正式库,还是snapshots库
val mavenRepositoryUrl =
if (isReleaseBuild) {
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
"https://oss.sonatype.org/content/repositories/snapshots/"
}
subprojects {
repositories {
mavenLocal()
/*maven(url = "http://192.168.1.12:18081/repository/public/") {
isAllowInsecureProtocol = true
}*/
maven("https://mirrors.huaweicloud.com/repository/maven/")
}
buildscript {
repositories {
mavenLocal()
/*maven(url = "http://192.168.1.12:18081/repository/public/") {
isAllowInsecureProtocol = true
}*/
maven("https://mirrors.huaweicloud.com/repository/maven/")
maven("https://plugins.gradle.org/m2/")
}
}
version = projectVersion
apply(plugin = "java")
apply(plugin = "java-library")
apply(plugin = "version-catalog")
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "idea")
apply(plugin = "eclipse")
tasks.withType<Test> {
// useJUnitPlatform()
}
afterEvaluate {
val originName = project.name.substring(7)
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
// options.compilerArgs.add("-parameters")
options.isDebug = true
options.isFork = true
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
plugins.withType<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
modularity.inferModulePath.set(true)
}
}
tasks.withType<Jar> {
archiveVersion.set(projectVersion)
manifest.attributes["Implementation-Title"] = project.name
manifest.attributes["Implementation-Version"] = projectVersion
manifest.attributes["Created-By"] =
"${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
}
val sourcesJar by tasks.registering(Jar::class) {
group = "jar"
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(project.the<SourceSetContainer>()["main"].allSource)
}
// javadoc
if (project.name != "debbie-dependencies") {
tasks.withType<Javadoc> {
isFailOnError = false
options {
encoding = "UTF-8"
charset("UTF-8")
}
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
val javadocJar by tasks.registering(Jar::class) {
group = "jar"
dependsOn(JavaPlugin.JAVADOC_TASK_NAME)
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
}
artifacts {
add("archives", javadocJar)
add("archives", sourcesJar)
}
}
tasks.withType<Delete> {
delete(File("$rootDir/$originName/out"))
delete(File("$rootDir/$originName/build"))
}
publishing {
publications {
create<MavenPublication>("uploadToMavenRepository") {
artifactId = project.name
group = "com.truthbean"
version = projectVersion
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
artifactId = project.name
name.set(project.name)
group = "com.truthbean"
version = projectVersion
description.set("a java microservice project")
url.set("http://www.truthbean.com/debbie")
licenses {
license {
name.set("Mulan PSL v2")
url.set("https://github.com/truthbean/debbie/blob/master/LICENSE")
}
}
developers {
developer {
id.set("truthbean")
name.set("Rogar·Q (TruthBean)")
email.set("[email protected]")
}
developer {
id.set("qu")
name.set("璩诗斌")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/TruthBean/debbie.git")
developerConnection.set("scm:git:ssh://github.com/TruthBean/debbie.git")
url.set("https://github.com/TruthBean/debbie")
}
issueManagement {
system.set("github")
url.set("https://github.com/truthbean/debbie/issues")
}
}
}
}
repositories {
maven {
url = uri(mavenRepositoryUrl)
credentials {
val sonatypeUsername: String? by project
username = if (sonatypeUsername == null || sonatypeUsername == "null") "anonymous" else sonatypeUsername
val sonatypePassword: String? by project
password = if (sonatypePassword == null || sonatypeUsername == "null") "anonymous" else sonatypePassword
}
}
}
}
// 进行数字签名
signing {
if(isReleaseBuild) {
sign(publishing.publications["uploadToMavenRepository"])
}
}
eclipse {
classpath {
isDownloadJavadoc = true
isDownloadSources = true
}
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
}
}