-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.gradle
364 lines (302 loc) · 11.4 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
import groovy.text.markup.MarkupTemplateEngine
import groovy.text.markup.TemplateConfiguration
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url "http://repo.spring.io/snapshot"
}
maven {
url "http://repo.spring.io/milestone"
}
maven {
url "http://repo.spring.io/release"
}
maven {
url "http://repo.spring.io/libs-staging-local/"
}
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${hasProperty("BOOT_VERSION") ? "${project.property("BOOT_VERSION")}" : "1.4.4.RELEASE"}"
if (hasProperty("docker")) {
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
//classpath 'org.codehaus.groovy:groovy-all:2.4.5'
}
}
def commonProject = project(':common')
def commonZipkinProject = project(':common-zipkin')
def commonZipkinProjectOld = project(':common-zipkin-old')
def commonZipkinStreamProject = project(':common-zipkin-stream')
def acceptanceTestsProject = project(':acceptance-tests')
def zipkinServerProject = project(':zipkin-server')
def eurekaProject = project(':eureka')
def configServerProject = project(':config-server')
def zookeeperServerProject = project(':zookeeper')
def techProjects = [commonProject, commonZipkinProject, commonZipkinProjectOld, commonZipkinStreamProject, acceptanceTestsProject,
eurekaProject, zipkinServerProject, configServerProject,
zookeeperServerProject]
def nonZipkinProjects = techProjects - zipkinServerProject
def nonDockerProjects = [commonProject, commonZipkinProject, commonZipkinProjectOld, commonZipkinStreamProject, acceptanceTestsProject]
def zipkinRelatedProjects = subprojects - nonZipkinProjects
allprojects {
apply plugin: 'java'
}
configure(subprojects) {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
ext {
dockerConfiguration = { int port ->
if (hasProperty("docker")) {
int debugPort = port - 1000
dependsOn 'build'
dryRun true
addFile("${libsDir}/${project.name}-${buildNrLoc}.jar", "/${project.name}/${project.name}.jar")
exposePort(port)
exposePort(debugPort)
// Random beacuse of https://wiki.apache.org/tomcat/HowTo/FasterStartUp
entryPoint(['java', '-Xmx64m', '-Xss1024k',
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort",
'-Djava.security.egd=file:/dev/./urandom', '-jar', "/${project.name}/${project.name}.jar"])
} else {
getLogger().debug("docker property is not set")
}
}
createDockerTaskWithPort = { int port ->
if (hasProperty("docker")) {
project.task([type: Docker], "docker", ext.dockerConfiguration.curry(port))
} else {
getLogger().debug("docker property is not set")
}
}
systemPropsFromGradle = {
project.gradle.startParameter.systemPropertiesArgs.entrySet().collect { "-D${it.key}=${it.value}" }
}
systemPropsFromGradleContains = { String key ->
project.gradle.startParameter.systemPropertiesArgs.containsKey(key)
}
whatToTest = { String propName ->
String whatToTestProp = "WHAT_TO_TEST"
return propName.equalsIgnoreCase(project.gradle.startParameter.systemPropertiesArgs.get(whatToTestProp)) ?:
propName.equalsIgnoreCase(System.getenv(whatToTestProp))
}
propOrSysEnvPresent = { String propName ->
project.hasProperty(propName) || systemPropsFromGradleContains(propName) || System.getenv(propName.toUpperCase())
}
moduleEnabled = { boolean enabled ->
if (!enabled) {
project.tasks*.enabled = false
}
}
oldSleuthPresent = {
String bom = "$BOM_VERSION".toString()
return ["Brixton", "Camden"].any { bom.contains(it) }
}
//buildNrLoc = project.hasProperty('buildNr') ? "${buildNr}" : "1.0.0"
//Since the migration is in progress - would keep the versions to snapshots
buildNrLoc = project.hasProperty('buildNr') ? "${buildNr}" : "1.0-SNAPSHOT"
}
group = 'io.spring.cloud.samples.brewery'
version = buildNrLoc
sourceCompatibility = '1.8'
configurations {
all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
// To prevent an accidental usage of groovy-all.jar and groovy.jar in different versions
// all modularized Groovy jars are replaced with groovy-all.jar by default.
if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != "groovy-all") {
details.useTarget("org.codehaus.groovy:groovy-all:${details.requested.version}")
}
}
}
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "http://repo.spring.io/snapshot"
}
maven {
url "http://repo.spring.io/milestone"
}
maven {
url "http://repo.spring.io/release"
}
maven {
url "http://repo.spring.io/libs-staging-local/"
}
jcenter()
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$BOM_VERSION"
if (hasProperty("BOOT_VERSION")) {
println "Using boot in version [${project.property("BOOT_VERSION")}]"
mavenBom "org.springframework.boot:spring-boot-dependencies:${project.property("BOOT_VERSION")}"
}
if (ext.whatToTest('SCS')) mavenBom "io.pivotal.spring.cloud:spring-cloud-services-dependencies:$SCS_VERSION"
}
}
task allDeps(type: DependencyReportTask) {}
}
logger.lifecycle("WHAT_TO_TEST is: System prop: [${project.gradle.startParameter.systemPropertiesArgs.get("WHAT_TO_TEST")}] , Env prop: [${System.getenv("WHAT_TO_TEST")}]")
configure(subprojects - zipkinServerProject - acceptanceTestsProject - zookeeperServerProject - configServerProject) {
dependencies {
compile 'org.projectlombok:lombok:1.16.6'
compile "org.springframework.cloud:spring-cloud-starter-sleuth"
if (!whatToTest('SCS')) compile "org.springframework.cloud:spring-cloud-starter-config"
if (whatToTest('SCS')) compile("io.pivotal.spring.cloud:spring-cloud-services-starter-config-client")
if (whatToTest('SCS')) compile("io.pivotal.spring.cloud:spring-cloud-services-starter-service-registry")
compile "org.springframework.cloud:spring-cloud-starter-hystrix"
compile "org.springframework.cloud:spring-cloud-starter-stream-${propOrSysEnvPresent('kafka') ? 'kafka' : 'rabbit'}"
if (!whatToTest('SLEUTH')) {
compile "org.springframework.cloud:spring-cloud-sleuth-stream"
}
compile "org.springframework.amqp:spring-amqp"
compile "io.dropwizard.metrics:metrics-core"
compile "io.dropwizard.metrics:metrics-graphite"
}
}
configure(zipkinRelatedProjects) {
dependencies {
if (whatToTest('SLEUTH')) {
compile "org.springframework.cloud:spring-cloud-starter-zipkin"
}
}
}
configure(nonDockerProjects) {
bootRepackage {
enabled = false
}
bootRun {
enabled = false
}
}
if (hasProperty("docker")) {
configure(subprojects - nonDockerProjects) {
apply plugin: 'docker'
docker {
baseImage 'frolvlad/alpine-oraclejdk8'
}
}
}
configure(subprojects) {
apply plugin: 'maven'
//Generate pom
task generatePom {
doLast {
pom {
withXml {
}.writeTo("$buildDir/tmp/pom.xml")
}
def pomXml = new XmlParser().parse(file("$buildDir/tmp/pom.xml"))
StringWriter stringWriter = new StringWriter()
PrintWriter pw = new PrintWriter(stringWriter)
XmlNodePrinter xmlNodePrinter = new XmlNodePrinter(pw)
xmlNodePrinter.preserveWhitespace = true
xmlNodePrinter.namespaceAware = false
xmlNodePrinter.print(pomXml.dependencies[0])
stringWriter.flush()
stringWriter.close()
def projectDepsXml = stringWriter.toString()
def model = [groupId : project.group,
artifactId : project.name,
version : buildNrLoc,
f8mpVersion : '3.2-SNAPSHOT',
springCloudVersion: 'Dalston.SR1',
springBootVersion : '1.5.4.RELEASE',
fabric8 : project.fabric8,
springBoot : project.springboot,
groovy : project.groovy,
projectDeps : projectDepsXml]
TemplateConfiguration tplConf = new TemplateConfiguration()
tplConf.autoNewLine = true
tplConf.autoIndent = true
tplConf.cacheTemplates = false
MarkupTemplateEngine engine = new MarkupTemplateEngine(tplConf)
def pomXmlTemplate = engine.createTemplate(file("$projectDir/../pom.tpl"))
pomXmlTemplate.make(model).writeTo(new FileWriter(file("$projectDir/pom.xml")))
file("$buildDir/tmp/pom.xml").delete()
}
}
//Utility for doing oc apply/delete from respective sub projects whereever its needed
project.ext.ocApply = {
def f8dir = new File("$projectDir/target/classes/META-INF/fabric8")
if (f8dir.exists()) {
def standardOutput = new ByteArrayOutputStream()
exec {
workingDir "$projectDir/target/classes/META-INF/fabric8"
commandLine 'oc', 'apply', '-f', 'openshift.yml'
}
return standardOutput.toString()
}
}
project.ext.ocDelete = {
def f8dir = new File("$projectDir/target/classes/META-INF/fabric8")
if (f8dir.exists()) {
def standardOutput = new ByteArrayOutputStream()
exec {
workingDir "$projectDir/target/classes/META-INF/fabric8"
commandLine 'oc', 'delete', '-f', 'openshift.yml'
}
return standardOutput.toString()
}
}
generatePom.onlyIf { project.hasProperty('fabric8') }
}
configure(subprojects - techProjects - commonZipkinProject - commonZipkinProjectOld - commonZipkinStreamProject) {
dependencies {
compile(commonProject)
if (whatToTest('SLEUTH')) {
if (oldSleuthPresent()) {
compile commonZipkinProjectOld
} else {
compile commonZipkinProject
}
}
if (whatToTest('SLEUTH_STREAM')) {
compile commonZipkinStreamProject
}
compile "org.springframework.boot:spring-boot-starter-actuator"
compile 'com.fasterxml.jackson.core:jackson-databind'
if (!whatToTest('CONSUL') && !whatToTest('EUREKA') && !whatToTest('SLEUTH_STREAM') && !whatToTest('SCS')) {
compile "org.springframework.cloud:spring-cloud-starter-zookeeper-discovery"
}
if (whatToTest('CONSUL')) {
compile "org.springframework.cloud:spring-cloud-starter-consul-discovery"
}
if (whatToTest('EUREKA') || whatToTest('SLEUTH_STREAM')) {
compile "org.springframework.cloud:spring-cloud-starter-eureka"
}
compile "org.springframework.cloud:spring-cloud-starter-feign"
compile "org.codehaus.jackson:jackson-mapper-asl:$jacksonMapper"
compile "org.codehaus.jackson:jackson-core-asl:$jacksonMapper"
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.jayway.jsonpath:json-path-assert:2.0.0'
compile 'org.yaml:snakeyaml'
compile 'org.hibernate:hibernate-validator'
compile "org.aspectj:aspectjrt"
runtime 'cglib:cglib-nodep:3.1'
runtime 'org.objenesis:objenesis:2.2'
runtime 'org.aspectj:aspectjweaver'
}
wrapper {
gradleVersion '3.3'
}
bootRun {
jvmArgs = systemPropsFromGradle()
}
test {
jvmArgs systemPropsFromGradle()
testLogging {
exceptionFormat = 'full'
showStandardStreams = true
}
}
}