-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
384 lines (334 loc) · 14.6 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
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
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
repositories {
/**
* https://maven.aliyun.com/mvn/view
* 仓库名称 代理源地址 使用地址
* central https://repo1.maven.org/maven2/ https://maven.aliyun.com/repository/central 或 https://maven.aliyun.com/nexus/content/repositories/central
* jcenter http://jcenter.bintray.com/ https://maven.aliyun.com/repository/jcenter 或 https://maven.aliyun.com/nexus/content/repositories/jcenter
* public central仓和jcenter仓的聚合仓 https://maven.aliyun.com/repository/public 或https://maven.aliyun.com/nexus/content/groups/public
* google https://maven.google.com/ https://maven.aliyun.com/repository/google 或 https://maven.aliyun.com/nexus/content/repositories/google
* gradle-plugin https://plugins.gradle.org/m2/ https://maven.aliyun.com/repository/gradle-plugin 或 https://maven.aliyun.com/nexus/content/repositories/gradle-plugin
* spring http://repo.spring.io/libs-milestone/ https://maven.aliyun.com/repository/spring 或 https://maven.aliyun.com/nexus/content/repositories/spring
* spring-plugin http://repo.spring.io/plugins-release/ https://maven.aliyun.com/repository/spring-plugin 或 https://maven.aliyun.com/nexus/content/repositories/spring-plugin
* grails-core https://repo.grails.org/grails/core https://maven.aliyun.com/repository/grails-core 或 https://maven.aliyun.com/nexus/content/repositories/grails-core
* apache snapshots https://repository.apache.org/snapshots/ https://maven.aliyun.com/repository/apache-snapshots 或 https://maven.aliyun.com/nexus/content/repositories/apache-snapshots
*/
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_SPRING_URL = "https://maven.aliyun.com/repository/spring"
def ALIYUN_SPRING_PLUGIN_URL = "https://maven.aliyun.com/repository/spring-plugin"
def ALIYUN_GRADLE_PLUGIN_URL = "https://maven.aliyun.com/repository/gradle-plugin"
def ALIYUN_GOOGLE_URL = "https://maven.aliyun.com/repository/google"
def ALIYUN_GRAILS_CORE_URL = "https://maven.aliyun.com/repository/grails-core"
def ALIYUN_APACHE_SNAPSHOTS_URL = "https://maven.aliyun.com/repository/apache-snapshots"
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')
|| url.startsWith('https://jcenter.bintray.com')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('http://repo.spring.io/libs-milestone')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_SPRING_URL."
remove repo
}
if (url.startsWith('http://repo.spring.io/plugins-release')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_SPRING_PLUGIN_URL."
remove repo
}
if (url.startsWith('https://plugins.gradle.org/m2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
remove repo
}
if (url.startsWith('https://maven.google.com')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
remove repo
}
if (url.startsWith('https://repo.grails.org/grails/core')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRAILS_CORE_URL."
remove repo
}
if (url.startsWith('https://repository.apache.org/snapshots/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_APACHE_SNAPSHOTS_URL."
remove repo
}
}
}
maven {
mavenLocal()
url ALIYUN_REPOSITORY_URL
mavenCentral()
gradlePluginPortal()
}
maven {
url ALIYUN_SPRING_URL
}
maven {
url ALIYUN_SPRING_PLUGIN_URL
}
maven {
url ALIYUN_GRADLE_PLUGIN_URL
}
maven {
url ALIYUN_GOOGLE_URL
}
maven {
url ALIYUN_GRAILS_CORE_URL
}
maven {
url ALIYUN_APACHE_SNAPSHOTS_URL
}
}
/**
* gradle所有的jar包文件坐标都在dependencies属性内放置
* 每一个jar包都具备以下特点
* 1.scope(作用域):gradle支持compile、runtime、testCompile、testRuntime四种scope
* compile:jar包在编译期与运行期依赖。
* runtime:jar包在运行期依赖。
* testCompile:jar包在测试编译期与运行期依赖。
* testRuntime:jar包在测试运行期依赖。
* 补充:
* providedCompile:jar包/依赖代码 仅在编译的时候需要,但是在运行时不需要依赖。
* providedCompile与compile,runtime区别:
* compile: 前提:apply plugin: 'war'或者apply plugin: 'java'
* providedCompile:前提:apply plugin: 'war',若前提为'java',则使用compileOnly
* runtime:前提:apply plugin: 'war'
* 以上所说的前提,如果不正确配置的话,就会遇到依赖包无法导入,以及runtime以及providedCompile无法使用的情况。
* 2. group:与maven的groupId一致。
* name:与maven的artifactId一致。
* version:与maven的version一致。
*/
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springIOVersion}"
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.1"
classpath('com.palantir.gradle.docker:gradle-docker:0.25.0')
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:2.7.0')
}
}
/**
* 定义插件
*/
plugins {
id "org.springframework.boot" version "${springBootVersion}" apply false
id "io.franzbecker.gradle-lombok" version "4.0.0" apply false
id 'com.google.cloud.tools.jib' version '2.7.0' apply false
}
/**
* 加载引入版本定义变量
*/
apply from: "$rootDir/versionsOfDependencies.gradle"
/**
* 引入所有模块的配置,包括父模块,子模块
*/
allprojects {
apply plugin: "jacoco"
apply plugin: "idea"
apply plugin: "eclipse"
// 私服地址
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_SPRING_URL = "https://maven.aliyun.com/repository/spring"
def ALIYUN_SPRING_PLUGIN_URL = "https://maven.aliyun.com/repository/spring-plugin"
def ALIYUN_GRADLE_PLUGIN_URL = "https://maven.aliyun.com/repository/gradle-plugin"
def ALIYUN_GOOGLE_URL = "https://maven.aliyun.com/repository/google"
def ALIYUN_GRAILS_CORE_URL = "https://maven.aliyun.com/repository/grails-core"
def ALIYUN_APACHE_SNAPSHOTS_URL = "https://maven.aliyun.com/repository/apache-snapshots"
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')
|| url.startsWith('https://jcenter.bintray.com')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('http://repo.spring.io/libs-milestone')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_SPRING_URL."
remove repo
}
if (url.startsWith('http://repo.spring.io/plugins-release')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_SPRING_PLUGIN_URL."
remove repo
}
if (url.startsWith('https://plugins.gradle.org/m2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
remove repo
}
if (url.startsWith('https://maven.google.com')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
remove repo
}
if (url.startsWith('https://repo.grails.org/grails/core')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRAILS_CORE_URL."
remove repo
}
if (url.startsWith('https://repository.apache.org/snapshots/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_APACHE_SNAPSHOTS_URL."
remove repo
}
}
}
maven {
mavenLocal()
url ALIYUN_REPOSITORY_URL
mavenCentral()
}
maven {
url ALIYUN_SPRING_URL
}
maven {
url ALIYUN_SPRING_PLUGIN_URL
}
maven {
url ALIYUN_GRADLE_PLUGIN_URL
}
maven {
url ALIYUN_GOOGLE_URL
}
maven {
url ALIYUN_GRAILS_CORE_URL
}
maven {
url ALIYUN_APACHE_SNAPSHOTS_URL
}
}
}
/**
* 定义只有子工程才会执行的task
*/
subprojects {
// 导入使用的插件
apply plugin: "java"
apply plugin: 'java-library'
apply plugin: "checkstyle"
apply plugin: "io.spring.dependency-management"
apply plugin: 'org.springframework.boot'
apply plugin: "org.junit.platform.gradle.plugin"
// jar包的group ,version配置
group "com.java.${rootProject.name}"
version '1.0-SNAPSHOT'
// jdk编译版本
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
// 指定gradle编译时,针对java文件使用 UTF-8 编码
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
/**
* 导入spring alibaba cloud的pom文件,能够免去自己管理版本
* PS: 在Spring官网指导上面有另外一种配置,那种配置需要配置main class,一会说明
*/
dependencyManagement {
imports {
mavenBom SpringBootPlugin.BOM_COORDINATES
mavenBom "com.squareup.okhttp3:okhttp-bom:4.9.0"
mavenBom "org.keycloak:keycloak-dependencies-server-all:${oauth2.revKeycloak}"
mavenBom "org.keycloak.bom:keycloak-adapter-bom:${oauth2.revKeycloak}"
}
/** 在这里定义公用依赖 */
dependencies {
/** 通用工具 */
dependency("org.projectlombok:lombok:${revLombok}")
dependency("org.apache.commons:commons-lang3:${revApacheCommonsLang3}")
dependency('com.google.guava:guava:20.0')
dependency('org.mapstruct:mapstruct:1.3.1.Final')
dependency('org.mapstruct:mapstruct-processor:1.3.1.Final')
dependency('org.mapstruct:mapstruct-jdk8:1.3.1.Final')
dependency('com.google.code.gson:gson:2.8.6')
dependency('com.alibaba:fastjson:1.2.75')
dependency("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springBootVersion}")
dependency("org.jboss.resteasy:resteasy-core:${oauth2.revJbossResteasy}")
dependency("org.jboss.resteasy:resteasy-jackson2-provider:3.12.1.Final")
dependency("com.h2database:h2:${revH2database}")
dependency("io.springfox:springfox-boot-starter:${revSwagger}")
dependency("com.github.xiaoymin:knife4j-spring-boot-starter:${revKnife4jStarter}")
dependency("org.springframework.experimental:spring-graalvm-native:0.8.5")
dependency("com.github.lianjiatech:retrofit-spring-boot-starter:2.2.5")
dependency("com.alibaba.csp:sentinel-core:1.8.0")
dependency("net.coobird:thumbnailator:0.4.13")
dependency("mysql:mysql-connector-java:8.0.18")
dependency("org.hsqldb:hsqldb:2.5.1")
dependency("org.flywaydb:flyway-core:7.5.0")
dependency("org.springframework.security.oauth:spring-security-oauth2:2.5.0.RELEASE")
}
}
ext {
generatedSourcesDir = file("${buildDir}/generated/sources")
generatedSourcesJavaDir = file("${project.generatedSourcesDir}/main/java")
}
idea.module {
sourceDirs += project.generatedSourcesJavaDir
generatedSourceDirs += project.generatedSourcesJavaDir
}
configurations {
all*.exclude module: 'commons-logging'
all*.exclude module: 'slf4j-log4j12'
all*.exclude module: 'log4j'
all*.exclude module: 'logback-classic'
all*.exclude group: "javax.servlet", module: "servlet-api"
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('org.springframework.boot:spring-boot-starter-log4j2')
if (JavaVersion.current().ordinal() >= JavaVersion.VERSION_1_9.ordinal()) {
// 查看文档 https://stackoverflow.com/questions/43574426/java-how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexceptio
// https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9-and-above#jaxb
implementation 'org.glassfish.jaxb:jaxb-runtime'
}
/*******************************
* Annotation Processors
*******************************/
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.mapstruct:mapstruct-processor'
/*******************************
* Compile Dependencies
*******************************/
api 'org.mapstruct:mapstruct-jdk8'
api 'com.google.guava:guava'
api 'org.apache.commons:commons-lang3'
/*******************************
* Compile Only Dependencies
*******************************/
compileOnly 'org.projectlombok:lombok'
/*******************************
* Runtime Only Dependencies
*******************************/
/*******************************
* Test Dependencies
*******************************/
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("io.specto:hoverfly-java-junit5:0.13.1")
testAnnotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor("org.mapstruct:mapstruct-processor")
testCompileOnly 'org.projectlombok:lombok'
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.0.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
}
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = project.generatedSourcesJavaDir
options.compilerArgs += [
"-Xlint:unchecked",
"-Xlint:deprecation",
"-s",
project.generatedSourcesJavaDir
]
}
compileTestJava {
options.compilerArgs += [
"-Xlint:unchecked",
"-Xlint:deprecation"
]
}
// 打包源码
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
test {
useJUnitPlatform()
}
}