-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
338 lines (313 loc) · 13.1 KB
/
build.gradle
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
ext {
println("Environment : JAVA_HOME=$System.env.JAVA_HOME")
println("Gradle Version : ${projectProperties.getProperty('gradleVersion')}")
println("Target JDK Version : ${projectProperties.getProperty('javaVersion')}")
println("Kotlin Version : $versions.kotlin")
println("Spring Boot Version : $versions.springBoot")
println("Acp Version : $versions.acp")
println("Encoding : ${projectProperties.getProperty('encoding')}")
println("Build Version : ${projectProperties.getProperty('version')}")
}
buildscript {
ext {
projectProperties = new Properties()
projectProperties.load(new FileInputStream("$rootDir/project.properties"))
}
apply from: "$rootDir/gradle/dependencies.gradle"
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath "org.jetbrains.kotlin:kotlin-allopen:$versions.kotlin"
classpath "org.jetbrains.kotlin:kotlin-noarg:$versions.kotlin"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$versions.springBoot"
}
repositories {
mavenLocal()
maven {
url = new URI(projectProperties.getProperty('mavenCentralUrl').toString())
allowInsecureProtocol = true
}
mavenCentral()
}
}
allprojects {
group project.group.toString().isBlank() ? projectProperties.getProperty('group') : "${projectProperties.getProperty('group')}.$project.group"
version projectProperties.getProperty('version')
apply from: "$rootDir/gradle/dependencies.gradle"
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-noarg'
apply plugin: 'kotlin-jpa'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply from: "$rootDir/gradle/environment.gradle"
sourceCompatibility = projectProperties.getProperty('javaVersion')
targetCompatibility = projectProperties.getProperty('javaVersion')
buildscript {
repositories {
mavenLocal()
maven {
url = new URI(projectProperties.getProperty('mavenCentralUrl').toString())
allowInsecureProtocol = true
}
mavenCentral()
}
}
repositories {
mavenLocal()
maven {
url = new URI(projectProperties.getProperty('mavenCentralUrl').toString())
allowInsecureProtocol = true
}
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:$versions.jupiter")
testImplementation("org.junit.platform:junit-platform-launcher:$versions.junitPlatform")
testImplementation "org.jetbrains.kotlin:kotlin-test"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.kotlinCoroutines"
}
task clearPj(type: Delete) {
delete 'release', 'build', 'target', 'out'
}
task copyJar(type: Copy) {
from(configurations.runtimeClasspath)
into('build/libs/dependencies')
}
task mapperFileCopy(type: Copy) {
copy {
from("src/main/java") {
include("**/*.xml")
include("**/*.json")
include("**/*.properties")
}
into("${buildDir}/classes/main")
}
copy {
from("src/test/java") {
include("**/*.xml")
include("**/*.json")
include("**/*.properties")
}
into("${buildDir}/classes/test")
}
copy {
from("src/main/kotlin") {
include("**/*.xml")
include("**/*.json")
include("**/*.properties")
}
into("${buildDir}/classes/main")
}
copy {
from("src/test/kotlin") {
include("**/*.xml")
include("**/*.json")
include("**/*.properties")
}
into("${buildDir}/classes/test")
}
}
jar {
dependsOn(copyJar)
manifest {
attributes('Implementation-Vendor': "${project.group}", 'Implementation-Title': "${project.name}", 'Implementation-Version': "${project.version}", 'Build-By': "Gradle ${projectProperties.getProperty('gradleVersion')}", 'Jvm-Version': "${projectProperties.getProperty('javaVersion')}", 'Kotlin-Version': "$versions.kotlin")
}
}
java {
withJavadocJar()
withSourcesJar()
}
javadoc {
options.charSet = projectProperties.getProperty('encoding')
options.docEncoding = projectProperties.getProperty('encoding')
options.encoding = projectProperties.getProperty('encoding')
options.addStringOption('Xdoclint:none', '-quiet')
}
compileJava {
options.encoding = projectProperties.getProperty('encoding')
}
compileJava.dependsOn(processResources)
compileTestJava {
options.encoding = projectProperties.getProperty('encoding')
}
compileKotlin {
kotlinOptions {
jvmTarget = projectProperties.getProperty('javaVersion')
}
}
compileKotlin.dependsOn(processResources)
compileTestKotlin {
kotlinOptions {
jvmTarget = projectProperties.getProperty('javaVersion')
}
}
test {
useJUnitPlatform()
exclude '**/*nobuild**'
}
def generateShell = { String appJarName ->
def memoryParam = jvmMemoryParam.get('default') as String
// generate linux shell
File templateFile = new File("$rootDir/doc/script/server.model")
List<String> lines = templateFile.readLines("UTF-8")
StringBuilder buffer = new StringBuilder()
for (String line : lines) {
buffer.append(line).append("\n")
}
String shellContent = buffer.toString()
shellContent = shellContent.replaceAll("@appJarName@", appJarName)
shellContent = shellContent.replaceAll("@jvmMemoryParam@", memoryParam)
StringBuilder jvmExtParamBuilder = new StringBuilder()
jvmExtParamBuilder.append("'")
if (project.hasProperty("active") && project.active != null && project.active != "") {
println("$project.name release finished: active=$project.active")
def envParam = jvmExtParam.get(project.active)
if (envParam != null) {
jvmExtParamBuilder.append("-Dacp_profile_active=$project.active" as String)
jvmExtParamBuilder.append(" -Dacp_nacos_addr=" + envParam['acp_nacos_addr'] as String)
jvmExtParamBuilder.append(" -Dacp_nacos_username=" + envParam['acp_nacos_username'] as String)
jvmExtParamBuilder.append(" -Dacp_nacos_password=" + envParam['acp_nacos_password'] as String)
jvmExtParamBuilder.append(" -Dacp_nacos_namespace=" + envParam['acp_nacos_namespace'] as String)
jvmExtParamBuilder.append(" -Dacp_log_path=" + envParam['acp_log_path'] as String)
}
}
jvmExtParamBuilder.append("'")
shellContent = shellContent.replaceAll("@jvmExtParam@", jvmExtParamBuilder.toString())
File outFile = new File("$rootDir/release/$project.name/server.sh")
Writer writer = new FileWriter(outFile)
writer.write(new String(shellContent.getBytes("UTF-8")))
writer.flush()
writer.close()
// generate k8s shell
File templateFileK8s = new File("$rootDir/doc/script/server-k8s.model")
List<String> linesK8s = templateFileK8s.readLines("UTF-8")
StringBuilder bufferK8s = new StringBuilder()
for (String line : linesK8s) {
bufferK8s.append(line).append("\n")
}
String shellContentK8s = bufferK8s.toString()
shellContentK8s = shellContentK8s.replaceAll("@appJarName@", appJarName)
shellContentK8s = shellContentK8s.replaceAll("@jvmMemoryParam@", memoryParam)
File outFileK8s = new File("$rootDir/release/$project.name/server-k8s.sh")
Writer writerK8s = new FileWriter(outFileK8s)
writerK8s.write(new String(shellContentK8s.getBytes("UTF-8")))
writerK8s.flush()
writerK8s.close()
} as Object
build {
doLast {
def needCopy = {
return ["admin-server",
"deploy-server",
"gateway-server",
"log-server",
"oauth-server",
"workflow-server",
"route-server"].toArray().contains("$project.name")
} as Object
if (needCopy()) {
def fileName = "$project.name" + "-" + "$project.version" + ".jar"
copy {
from file("${buildDir}/libs/" + fileName)
into "$rootDir/release/$project.name"
}
copy {
from "${buildDir}/resources/main"
into "$rootDir/release/$project.name"
}
generateShell(fileName)
}
}
}
publishing {
publications {
maven(MavenPublication) {
//指定group/artifact/version信息
groupId project.group
artifactId project.name
version project.version
//打包类型 war: components.web jar: components.java
from components.java
pom {
name = "acp-admin-cloud"
description = "基于acp构建的cloud应用"
url = "https://github.com/zhangbinhub/acp-admin-cloud"
licenses {
license {
name = "Apache License Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0"
}
}
developers {
developer {
id = "hangbinhub"
name = "zhangbin"
email = "zhangbin1010@qq.com"
}
}
scm {
connection = "scm:git:https://github.com/zhangbinhub/acp-admin-cloud.git"
developerConnection = "scm:git:https://github.com/zhangbinhub/acp-admin-cloud.git"
url = "https://github.com/zhangbinhub/acp-admin-cloud"
}
}
}
}
repositories {
maven {
def file = new File("$rootDir/gradle.properties")
def releaseUrl = 'http://maven/repository'
def snapshotUrl = 'http://maven/repository'
def name = ''
def pwd = ''
if (file.exists()) {
def gradleProperties = new Properties()
gradleProperties.load(new FileInputStream(file))
releaseUrl = gradleProperties.containsKey('mavenUploadUrlRelease') ? "${mavenUploadUrlRelease}" : releaseUrl
snapshotUrl = gradleProperties.containsKey('mavenUploadUrlSnapshot') ? "${mavenUploadUrlSnapshot}" : snapshotUrl
name = gradleProperties.containsKey('mavenUserName') ? "${mavenUserName}" : name
pwd = gradleProperties.containsKey('mavenUserName') ? "${mavenPassword}" : pwd
}
url = version.endsWith('-SNAPSHOT') ? new URI(snapshotUrl) : new URI(releaseUrl)
allowInsecureProtocol = true
//认证用户和密码
credentials {
username name
password pwd
}
}
}
}
signing {
required {
def file = new File("$rootDir/gradle.properties")
if (file.exists()) {
def gradleProperties = new Properties()
gradleProperties.load(new FileInputStream(file))
if (!gradleProperties.getProperty('signing.keyId', '').isBlank()) {
return true
}
}
return false
}
sign publishing.publications.maven
}
task release(dependsOn: [build, copyJar])
def needDeployProject = {
return ["acp-admin-cloud-constant",
"acp-admin-cloud-dependencies"].toArray().contains("$project.name")
} as Object
publish.onlyIf { needDeployProject() }
generateMetadataFileForMavenPublication.onlyIf { needDeployProject() }
generatePomFileForMavenPublication.onlyIf { needDeployProject() }
publishAllPublicationsToMavenRepository.onlyIf { needDeployProject() }
publishMavenPublicationToMavenLocal.onlyIf { needDeployProject() }
publishMavenPublicationToMavenRepository.onlyIf { needDeployProject() }
publishToMavenLocal.onlyIf { needDeployProject() }
}