forked from wiremock/wiremock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
493 lines (420 loc) · 15.5 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
buildscript {
repositories {
maven {
url "https://oss.sonatype.org"
}
mavenCentral()
}
dependencies {
classpath group: 'org.ajoberstar', name: 'gradle-plugins', version: '0.1.1'
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
}
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'idea'
apply plugin: 'project-report'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = 1.7
targetCompatibility = 1.7
group = 'com.github.tomakehurst'
version = '2.18.0'
def shouldPublishLocally = System.getProperty('LOCAL_PUBLISH')
def versions = [
jackson: '2.8.11',
jacksonDatabind: '2.8.11.2',
jetty : '9.2.24.v20180105', // 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
xmlUnit: '2.5.1'
]
repositories {
mavenCentral()
}
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:20.0"
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.5"
compile "org.xmlunit:xmlunit-core:$versions.xmlUnit"
compile "org.xmlunit:xmlunit-legacy:$versions.xmlUnit"
compile "com.jayway.jsonpath:json-path:2.4.0"
compile "org.slf4j:slf4j-api:1.7.12"
compile "net.sf.jopt-simple:jopt-simple:5.0.3"
compile("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'
compile 'com.github.jknack:handlebars:4.0.6', {
exclude group: 'org.mozilla', module: 'rhino'
}
compile 'com.github.jknack:handlebars-helpers:4.0.6'
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.littleshoot:littleproxy:1.1.2'
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')
}
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"
exceptionFormat "full"
}
}
configurations {
provided
shadowJar
thinJarPom
standaloneJarPom
}
sourceSets {
main { compileClasspath += configurations.provided }
}
eclipse {
classpath {
plusConfigurations += configurations.provided
}
}
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.common", 'wiremock.com.google.common'
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"
dependencies {
exclude(dependency('junit:junit'))
}
}
def releaseDirUrl
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
}
def thinJarPomPath = "${project.buildDir}/publications/thinJar/pom-default.xml"
def 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
}
final pomInfo = {
resolveStrategy = Closure.DELEGATE_FIRST
name 'WireMock'
description 'A web service test double for all occasions'
url 'http://wiremock.org'
scm {
connection 'https://tomakehurst@github.com/tomakehurst/wiremock.git'
developerConnection 'https://tomakehurst@github.com/tomakehurst/wiremock.git'
url 'https://tomakehurst@github.com/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) {
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() {
it.scope*.value = 'compile'
}
}
}
standaloneJar(MavenPublication) {
artifactId "${project.name}-standalone"
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 << {
def REQUIRED_GIT_BRANCH = 'master'
println "Using Java version: ${System.getProperty('java.runtime.version')}"
assert System.getProperty('java.runtime.version').startsWith('1.7'), "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 << {
if (!shouldPublishLocally) {
println "git tag ${version}".execute().text
println "git push origin --tags".execute().text
}
}
task signAll {
dependsOn signJars, signThinJar, signShadowJar, signThinJarPom, signStandaloneJarPom
}
task npmInstall(type: Exec) {
workingDir 'docs-v2'
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-v2'
if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
commandLine 'cmd', '/c', 'npm', 'run', 'apidocs'
} else {
commandLine 'npm', 'run', 'apidocs'
}
}
jar.dependsOn generateApiDocs
processResources.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 'set-release-dir' << {
if (releaseDir) {
releaseDirUrl = 'file://' + releaseDir
if (!releaseDirUrl.endsWith('/')) {
releaseDirUrl = releaseDirUrl + '/';
}
tasks.uploadArchives.repositories.mavenDeployer.repository.url = releaseDirUrl
println 'Release dir set to: ' + releaseDirUrl
} else {
logger.error "Please specify release dir e.g. -P/home/me/.m2/repository"
System.exit(1)
}
}
task 'bump-patch-version' << {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'docs-v2/_config.yml' : { "wiremock_version: ${it}" },
'src/main/resources/raml/wiremock-admin-api.raml': { "version: ${it}" }
]
def currentVersion = project.version
def 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' << {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'docs-v2/_config.yml' : { "wiremock_version: ${it}" },
'src/main/resources/raml/wiremock-admin-api.raml': { "version: ${it}" }
]
def currentVersion = project.version
def 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(project.version.substring(0, project.version.indexOf('.')))
}
int getMinorVersion() {
Integer.valueOf(project.version.substring(project.version.indexOf('.') + 1, project.version.lastIndexOf('.')))
}
int getPatchVersion() {
Integer.valueOf(project.version.substring(project.version.lastIndexOf('.') + 1))
}
task wrapper(type: Wrapper) {
gradleVersion = '3.1'
}
task 'add-copyright-headers' << {
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;
}
}
}