forked from wiremock/wiremock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
552 lines (472 loc) · 19.2 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
allprojects {
buildscript {
repositories {
jcenter()
maven {
url "https://oss.sonatype.org"
}
mavenCentral()
}
}
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'project-report'
group = 'com.github.tomakehurst'
version = '2.25.1'
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
def versionSets = [
java7: [
handlebars : '4.0.7',
jetty : '9.2.28.v20190418', // Please don't raise PRs upgrading this to the latest version as it drops Java 7 support. See https://github.com/tomakehurst/wiremock/issues/407 and https://github.com/tomakehurst/wiremock/pull/887 for details
guava : '20.0',
jackson : '2.10.0',
jacksonDatabind: '2.10.0',
xmlUnit : '2.6.2'
],
java8: [
handlebars : '4.1.2',
jetty : '9.4.20.v20190813',
guava : '27.0.1-jre',
jackson : '2.10.0',
jacksonDatabind: '2.10.0',
xmlUnit : '2.6.2'
]
]
def isJava7 = project.name in ['wiremock', 'java7']
def versions = isJava7 ?
versionSets.java7 :
versionSets[project.name]
dependencies {
compile "org.eclipse.jetty:jetty-server:$versions.jetty"
compile "org.eclipse.jetty:jetty-servlet:$versions.jetty"
compile "org.eclipse.jetty:jetty-servlets:$versions.jetty"
compile "org.eclipse.jetty:jetty-webapp:$versions.jetty"
compile "com.google.guava:guava:$versions.guava"
compile "com.fasterxml.jackson.core:jackson-core:$versions.jackson",
"com.fasterxml.jackson.core:jackson-annotations:$versions.jackson",
"com.fasterxml.jackson.core:jackson-databind:$versions.jacksonDatabind"
compile "org.apache.httpcomponents:httpclient:4.5.6"
compile "org.xmlunit:xmlunit-core:$versions.xmlUnit"
compile "org.xmlunit:xmlunit-legacy:$versions.xmlUnit", {
exclude group: 'junit', module: 'junit'
}
compile "org.xmlunit:xmlunit-placeholders:$versions.xmlUnit"
compile "com.jayway.jsonpath:json-path:2.4.0"
compile "org.ow2.asm:asm:7.0"
compile "org.slf4j:slf4j-api:1.7.12"
compile "net.sf.jopt-simple:jopt-simple:5.0.3"
compileOnly("junit:junit:4.12") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
compile 'org.apache.commons:commons-lang3:3.7'
compile 'com.flipkart.zjsonpatch:zjsonpatch:0.4.4', {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
}
compile "com.github.jknack:handlebars:$versions.handlebars", {
exclude group: 'org.mozilla', module: 'rhino'
}
compile("com.github.jknack:handlebars-helpers:$versions.handlebars") {
exclude group: 'org.mozilla', module: 'rhino'
}
compile 'commons-fileupload:commons-fileupload:1.4'
testCompile "junit:junit:4.12"
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile("org.jmock:jmock:2.5.1") {
exclude group: "junit", module: "junit-dep"
exclude group: "org.hamcrest", module: "hamcrest-core"
exclude group: "org.hamcrest", module: "hamcrest-library"
}
testCompile("org.jmock:jmock-junit4:2.5.1") {
exclude group: "junit", module: "junit-dep"
exclude group: "org.hamcrest", module: "hamcrest-core"
exclude group: "org.hamcrest", module: "hamcrest-library"
}
testCompile "org.skyscreamer:jsonassert:1.2.3"
testCompile 'com.toomuchcoding.jsonassert:jsonassert:0.4.12'
testCompile 'org.awaitility:awaitility:2.0.0'
testCompile "com.googlecode.jarjar:jarjar:1.3"
testCompile "commons-io:commons-io:2.4"
testCompile 'org.scala-lang:scala-library:2.11.12'
testCompile 'org.apache.httpcomponents:httpmime:4.5'
testRuntime 'org.slf4j:slf4j-log4j12:1.7.12'
testRuntime files('src/test/resources/classpath file source/classpathfiles.zip', 'src/test/resources/classpath-filesource.jar')
def littleProxyDep = isJava7 ? 'org.littleshoot:littleproxy:1.1.2' : 'net.jockx:littleproxy:1.1.3'
testCompile (littleProxyDep) {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'org.apache.commons', module: 'commons-lang3'
exclude group: 'org.slf4j', module: 'slf4j-api'
}
}
compileTestJava {
options.encoding = 'UTF-8'
}
test {
// Set the timezone for testing somewhere other than my machine to increase the chances of catching timezone bugs
systemProperty 'user.timezone', 'Australia/Sydney'
exclude 'ignored/**'
maxParallelForks = 3
testLogging {
events "FAILED", "SKIPPED"
exceptionFormat "full"
}
}
final DOCS_DIR = project(':').rootDir.getAbsolutePath() + '/docs-v2'
task npmInstall(type: Exec) {
workingDir DOCS_DIR
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'npm', 'i'
} else {
commandLine 'npm', 'i'
}
}
task generateApiDocs(type: Exec) {
dependsOn npmInstall
workingDir DOCS_DIR
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'npm', 'run', 'apidocs'
} else {
commandLine 'npm', 'run', 'apidocs'
}
}
processResources.dependsOn generateApiDocs
}
subprojects {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
sourceSets {
main.java.srcDir project(':').sourceSets.main.java
test.java.srcDir project(':').sourceSets.test.java
test.scala.srcDir project(':').sourceSets.test.scala
}
processResources {
from project(':').sourceSets.main.resources.srcDirs
}
processTestResources {
from project(':').sourceSets.test.resources.srcDirs
}
dependencies {
testRuntime files('../src/test/resources/classpath file source/classpathfiles.zip', '../src/test/resources/classpath-filesource.jar')
}
def shouldPublishLocally = System.getProperty('LOCAL_PUBLISH')
configurations {
shadowJar
thinJarPom
standaloneJarPom
}
jar {
manifest {
attributes("Main-Class": "com.github.tomakehurst.wiremock.standalone.WireMockServerRunner")
}
}
shadowJar {
baseName = 'wiremock-standalone'
classifier = ''
relocate "org.mortbay", 'wiremock.org.mortbay'
relocate "org.eclipse", 'wiremock.org.eclipse'
relocate "org.codehaus", 'wiremock.org.codehaus'
relocate "com.google", 'wiremock.com.google'
relocate "com.google.thirdparty", 'wiremock.com.google.thirdparty'
relocate "com.fasterxml.jackson", 'wiremock.com.fasterxml.jackson'
relocate "org.apache", 'wiremock.org.apache'
relocate "org.xmlunit", 'wiremock.org.xmlunit'
relocate "org.hamcrest", 'wiremock.org.hamcrest'
relocate "org.skyscreamer", 'wiremock.org.skyscreamer'
relocate "org.json", 'wiremock.org.json'
relocate "net.minidev", 'wiremock.net.minidev'
relocate "com.jayway", 'wiremock.com.jayway'
relocate "org.objectweb", 'wiremock.org.objectweb'
relocate "org.custommonkey", "wiremock.org.custommonkey"
relocate "com.flipkart", "wiremock.com.flipkart"
relocate "net.sf", "wiremock.net.sf"
relocate "com.github.jknack", "wiremock.com.github.jknack"
relocate "org.antlr", "wiremock.org.antlr"
relocate "javax.servlet", "wiremock.javax.servlet"
relocate "org.checkerframework", "wiremock.org.checkerframework"
dependencies {
exclude(dependency('junit:junit'))
}
mergeServiceFiles()
exclude 'META-INF/maven/javax.servlet/**'
}
def repoUser
def repoPassword
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task testJar(type: Jar, dependsOn: testClasses) {
classifier = 'tests'
from sourceSets.test.output
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
String thinJarPomPath = "${project.buildDir}/publications/thinJar/pom-default.xml"
String standaloneJarPomPath = "${project.buildDir}/publications/standaloneJar/pom-default.xml"
artifacts {
archives sourcesJar
archives javadocJar
archives shadowJar
archives testJar
thinJarPom new File(thinJarPomPath)
standaloneJarPom new File(standaloneJarPomPath)
}
signing {
required {
!version.toString().contains("SNAPSHOT") && (gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))
}
sign configurations.archives
}
task signJars(type: Sign, dependsOn: [javadocJar, sourcesJar, testJar]) {
sign javadocJar
sign sourcesJar
sign testJar
}
task signThinJar(type: Sign, dependsOn: jar) {
sign jar
}
task signShadowJar(type: Sign, dependsOn: shadowJar) {
sign shadowJar
}
task signThinJarPom(type: Sign, dependsOn: 'generatePomFileForThinJarPublication') {
outputs.upToDateWhen { false }
sign new File(thinJarPomPath)
}
task signStandaloneJarPom(type: Sign, dependsOn: 'generatePomFileForStandaloneJarPublication') {
outputs.upToDateWhen { false }
sign new File(standaloneJarPomPath)
}
if (!this.hasProperty('sonatypeUser')) {
repoUser = 'default'
} else {
repoUser = sonatypeUser
}
if (!this.hasProperty('sonatypePassword')) {
repoPassword = 'default'
} else {
repoPassword = sonatypePassword
}
def pomInfo = {
resolveStrategy = Closure.DELEGATE_FIRST
name 'WireMock'
description 'A web service test double for all occasions'
url 'http://wiremock.org'
scm {
connection 'https://[email protected]/tomakehurst/wiremock.git'
developerConnection 'https://[email protected]/tomakehurst/wiremock.git'
url 'https://[email protected]/tomakehurst/wiremock.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'tomakehurst'
name 'Tom Akehurst'
}
}
}
publishing {
repositories {
maven {
URL localRepo = new File("${System.getProperty('user.home')}/.m2/repository").toURI().toURL()
URL repoUrl = shouldPublishLocally ? localRepo : URI.create('https://oss.sonatype.org/service/local/staging/deploy/maven2').toURL()
url repoUrl
if (!shouldPublishLocally) {
credentials {
username repoUser
password repoPassword
}
}
}
}
publications {
thinJar(MavenPublication) {
artifactId "${jar.baseName}"
from components.java
artifact sourcesJar
artifact javadocJar
artifact testJar
(signJars.signatures + signThinJar.singleSignature).each { signature ->
artifact(signature) {
classifier = signature.classifier == '' ? null : signature.classifier
extension = "jar.${signature.extension}"
}
}
artifact(signThinJarPom.singleSignature) {
extension = 'pom.asc'
}
pom.withXml {
asNode().children().last() + pomInfo
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
if (it.name in VARIABLE_VERSION_ARTIFACTS.keySet() && it.version != VARIABLE_VERSION_ARTIFACTS[it.name]) {
it.remove()
} else {
it.scope*.value = 'compile'
}
}
}
}
standaloneJar(MavenPublication) { publication ->
artifactId "${jar.baseName}-standalone"
project.shadow.component(publication)
// from components.shadow
artifact sourcesJar
artifact javadocJar
(signJars.signatures + signShadowJar.singleSignature).each { signature ->
artifact(signature) {
classifier = signature.classifier == '' ? null : signature.classifier
extension = "jar.${signature.extension}"
}
}
artifact(signStandaloneJarPom.singleSignature) {
extension = 'pom.asc'
}
pom.packaging 'jar'
pom.withXml {
asNode().children().last() + pomInfo
}
}
}
}
task checkReleasePreconditions {
doLast {
def REQUIRED_GIT_BRANCH = 'master'
println "Using Java version: ${System.getProperty('java.runtime.version')}"
println "Required version: ${project.targetCompatibility.toString()}"
assert System.getProperty('java.runtime.version').startsWith(project.targetCompatibility.toString()), "Must release with Java 7 to avoid collection bug"
def currentGitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
assert currentGitBranch == REQUIRED_GIT_BRANCH || shouldPublishLocally, "Must be on the $REQUIRED_GIT_BRANCH branch in order to release to Sonatype"
}
}
publish.dependsOn checkReleasePreconditions
task addGitTag {
doLast {
if (!shouldPublishLocally) {
println "git tag ${version}".execute().text
println "git push origin --tags".execute().text
}
}
}
task signAll {
dependsOn signJars, signThinJar, signShadowJar, signThinJarPom, signStandaloneJarPom
}
jar.dependsOn generateApiDocs
task deleteGeneratedApiDocs(type: Delete) {
delete "src/main/resources/swagger"
}
clean.dependsOn deleteGeneratedApiDocs
task release {
dependsOn 'generatePomFileForThinJarPublication', 'generatePomFileForStandaloneJarPublication'
dependsOn clean, jar, shadowJar, signAll, publish, addGitTag
}
}
task 'bump-patch-version' {
doLast {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'docs-v2/_config.yml' : { "wiremock_version: ${it}" },
'src/main/resources/swagger/wiremock-admin-api.yaml': { "version: ${it}" }
]
def currentVersion = project.version
String nextVersion = "${majorVersion}.${minorVersion}.${patchVersion + 1}"
filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = new File(fileName)
def lineWithVersionTemplateList = lineWithVersionTemplates instanceof List ?
lineWithVersionTemplates :
[lineWithVersionTemplates]
lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
}
}
}
task 'bump-minor-version' {
doLast {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'docs-v2/_config.yml' : { "wiremock_version: ${it}" },
'src/main/resources/swagger/wiremock-admin-api.yaml': { "version: ${it}" }
]
def currentVersion = project.version
String nextVersion = "${majorVersion}.${minorVersion + 1}.0"
filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = new File(fileName)
def lineWithVersionTemplateList = lineWithVersionTemplates instanceof List ?
lineWithVersionTemplates :
[lineWithVersionTemplates]
lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
}
}
}
int getMajorVersion() {
Integer.valueOf((String) project.version.substring(0, project.version.indexOf('.')))
}
int getMinorVersion() {
Integer.valueOf((String) project.version.substring(project.version.indexOf('.') + 1, project.version.lastIndexOf('.')))
}
int getPatchVersion() {
Integer.valueOf((String) project.version.substring(project.version.lastIndexOf('.') + 1))
}
task 'add-copyright-headers' {
doLast {
def copyrightNotice = """/*
* Copyright (C) 2011 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"""
def srcDir = new File('src')
srcDir.eachFileRecurse { file ->
if (file.name.endsWith(".java") && !file.text.contains(copyrightNotice)) {
println "Adding copyright header to $file.path"
def newFileText = copyrightNotice + file.text
file.text = newFileText
}
}
}
}