This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
271 lines (239 loc) · 8.38 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
buildscript {
ext {
springBootVersion = "2.0.2.RELEASE"
nodePluginVersion = "1.2.0"
propdepsPluginVersion = "0.0.9.RELEASE"
jwtVersion = "0.9.0"
lombokVersion = "1.16.20"
refVersion = "0.9.11"
flywayVersion = "5.0.7"
envSet = false
buildPropertiesFilePath = "./build/resources/main/application.properties"
snippetsDir = file("build/generated-snippets")
apiDocsFolder = "apidocs"
}
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/plugins-release" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "com.moowork.gradle:gradle-node-plugin:${nodePluginVersion}"
classpath "io.spring.gradle:propdeps-plugin:${propdepsPluginVersion}"
classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.3"
classpath "net.saliman:gradle-cobertura-plugin:2.3.1"
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2"
}
}
plugins {
id "org.asciidoctor.convert" version "1.5.3"
// coverage reports for coveralls.io
id 'net.saliman.cobertura' version '2.3.1'
id "com.github.kt3k.coveralls" version "2.8.2"
}
apply plugin: "io.spring.dependency-management"
apply plugin: "propdeps"
apply plugin: "propdeps-maven"
apply plugin: "propdeps-idea"
apply plugin: "propdeps-eclipse"
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "org.springframework.boot"
apply plugin: "war"
apply plugin: "com.moowork.node"
apply plugin: "org.asciidoctor.convert"
apply plugin: "net.saliman.cobertura"
apply plugin: "com.github.kt3k.coveralls"
group = "com.gms"
version = "0.0.1"
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
node {
download = false
nodeModulesDir = file("../client")
}
dependencies {
compile ("org.springframework.boot:spring-boot-starter-hateoas")
compile ("org.springframework.boot:spring-boot-starter-data-jpa")
compile ("org.springframework.boot:spring-boot-starter-data-rest")
compile ("org.springframework.boot:spring-boot-starter-mail")
compile ("org.springframework.boot:spring-boot-starter-security")
compile ("io.jsonwebtoken:jjwt:${jwtVersion}")
compile ("org.springframework.boot:spring-boot-starter-web")
compile ("org.reflections:reflections:${refVersion}")
compile ("org.flywaydb:flyway-core:${flywayVersion}")
compileOnly ("org.projectlombok:lombok:${lombokVersion}")
runtime ("org.springframework.boot:spring-boot-devtools")
runtime ("org.postgresql:postgresql")
testCompile ("com.jayway.jsonpath:json-path")
testCompile ("org.springframework.boot:spring-boot-starter-test")
testCompile ("org.springframework.restdocs:spring-restdocs-mockmvc")
testCompile ("org.springframework.security:spring-security-test")
optional ("org.springframework.boot:spring-boot-configuration-processor")
}
//region custom tasks
//region client task
task clientBuild(type: NpmTask, dependsOn: ["copyClientDocBuild"]) {
group = "client tasks"
description = "Compiles client side folder for production"
args = ["run", "build"]
}
task copyClientBuild(type: Copy, dependsOn: ["clientBuild"]) {
group = "client tasks"
description = "Checks all client side resources are ready for deployment and copy them into the `static` folder"
from "../client/dist"
into "build/resources/main/static"
}
task clientDocBuild(type: NpmTask) {
group = "client tasks"
description = "Compiles client side documentation folder for production"
args = ["run", "builddoc"]
}
task copyClientDocBuild(type: Copy, dependsOn: ["clientDocBuild"]) {
group = "client tasks"
description = "Checks all client app documentation resources are ready for deployment and copy them into the `static` folder"
from "../client/documentation"
into "build/resources/main/static/appdocs"
}
task cleanAll(type: Delete, dependsOn: ["clean"]) {
group = "build"
description = "Deletes de build directory from server and client modules"
delete '../client/documentation', '../client/dist', '../client/coverage'
followSymlinks = true
}
//endregion
//region environments config
task setDevConfig() {
group = "other"
description = "Sets the environment for development mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "development") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "development")
}
envSet = true
}
}
doLast {
if (getSpringAppPropertyInBuild("spring.profiles.active") == "development") {
println "Environment set for development mode..."
}
}
}
task setTestingConfig() {
group = "other"
description = "Sets the environment for testing mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "test") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "test")
}
envSet = true
}
}
doLast {
if (getSpringAppPropertyInBuild("spring.profiles.active") == "test") {
println "Environment set for testing mode..."
}
}
}
task setProductionConfig() {
group = "other"
description = "Sets the environment for production mode"
doFirst {
def p = getSpringAppPropertyInBuild("spring.profiles.active")
if (p && p != "production") {
ant.propertyfile(file: buildPropertiesFilePath) {
entry(key: "spring.profiles.active", value: "production")
}
envSet = true
}
}
doLast {
if (getSpringAppPropertyInBuild("spring.profiles.active") == "production") {
println 'Environment set for production mode...'
}
}
}
@SuppressWarnings("GrMethodMayBeStatic")
private String getSpringAppPropertyInBuild(String key, String filePath = null){
def props = new Properties()
def propFile = new File(filePath ?: buildPropertiesFilePath)
def p = null
if (propFile.exists() && propFile.canRead()){
props.load(new FileInputStream(propFile))
if (props!=null && props.containsKey(key)) {
p = props[key]
}
}
return p
}
//endregion
//region control enabled tasks
clientBuild.enabled = buildClient()
copyClientBuild.enabled = buildClient()
clientDocBuild.enabled = buildDocClient()
copyClientDocBuild.enabled = buildDocClient()
task resetConfigTaskState(type: Exec) {
group = "other"
description = "Resets the custom tasks to their original state"
doLast {
clientBuild.enabled = buildClient()
copyClientBuild.enabled = buildClient()
clientDocBuild.enabled = buildDocClient()
copyClientDocBuild.enabled = buildDocClient()
setDevConfig.enabled = true
setTestingConfig.enabled = true
setProductionConfig.enabled = true
}
}
//endregion
//region api docs
asciidoctor {
//noinspection GroovyAssignabilityCheck
attributes "snippets": snippetsDir
inputs.dir snippetsDir
outputDir "build/asciidoc"
dependsOn test
sourceDir "src/main/asciidoc"
}
task processApiDocs(type: Copy, dependsOn: asciidoctor) {
group = "build"
description = "Copies de api documentation to the destinated folder"
from "${asciidoctor.outputDir}/html5"
into "build/resources/main/static/" + (apiDocsFolder as String)
}
//endregion
//endregion
cobertura.coverageFormats = ['html', 'xml'] // coveralls plugin depends on xml format report
resetConfigTaskState.mustRunAfter(bootRun, bootWar, clean)
clean.dependsOn(setDevConfig)
bootRun.dependsOn(setDevConfig)
test {
dependsOn setTestingConfig
outputs.dir snippetsDir
}
testClasses.dependsOn(setTestingConfig)
bootWar {
dependsOn setProductionConfig, processApiDocs, copyClientBuild
baseName = getAppName()
}
// In order to generate our own metadata by Using the Annotation Processor
compileJava.dependsOn(processResources)
private boolean buildClient() {
return project.getProperties().get("client")
}
private boolean buildDocClient() {
return project.getProperties().get("clientDoc")
}
private String getAppName() {
return getSpringAppPropertyInBuild("spring.application.name", "./src/main/resources/application.properties")
}