forked from wiremock/wiremock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
434 lines (372 loc) · 13.9 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
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.2'
}
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.1.11'
def shouldPublishLocally = System.getProperty('LOCAL_PUBLISH')
def versions = [
jackson: '2.6.1',
jetty : '9.2.13.v20150730'
]
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:18.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.jackson"
compile "org.apache.httpcomponents:httpclient:4.5.1"
compile 'org.xmlunit:xmlunit-core:2.1.1'
compile 'org.xmlunit:xmlunit-legacy:2.1.1'
compile "com.jayway.jsonpath:json-path:2.0.0"
compile "org.slf4j:slf4j-api:1.7.12"
compile "net.sf.jopt-simple:jopt-simple:4.9"
compile("junit:junit:4.12") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.flipkart.zjsonpatch:zjsonpatch:0.2.1'
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.googlecode.jarjar:jarjar:1.3"
testCompile "commons-io:commons-io:2.4"
testCompile 'org.scala-lang:scala-library:2.11.8'
testRuntime 'org.slf4j:slf4j-log4j12:1.7.12'
testRuntime files('src/test/resources/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
}
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"
dependencies {
exclude(dependency('junit:junit'))
}
}
def releaseDirUrl
def repoUser
def repoPassword
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
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
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]) {
sign javadocJar
sign sourcesJar
}
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://[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
credentials {
username repoUser
password repoPassword
}
}
}
publications {
thinJar(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
(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 << {
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 == 'master', 'Must be on the master branch in order to release'
}
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 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-version' << {
def baseVersion = '2.1'
def filesWithVersion = [
'build.gradle' : { "version = '${baseVersion}.${it}" },
'docs-v2/_config.yml' : { "wiremock_version: ${baseVersion}.${it}" },
]
def gradleBuildFile = new File('build.gradle')
int currentMinorVersion
gradleBuildFile.text.find ~/version = '${baseVersion}.([0-9]+)/, { match, minorVersion ->
currentMinorVersion = Integer.valueOf(minorVersion)
int nextMinorVersion = currentMinorVersion + 1
filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = new File(fileName)
def lineWithVersionTemplateList = lineWithVersionTemplates instanceof List ?
lineWithVersionTemplates :
[lineWithVersionTemplates];
lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentMinorVersion)
def newLine = lineWithVersionTemplate.call(nextMinorVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine);
}
}
}
}
task 'bump-version-down' << {
def filesWithVersion = [
'build.gradle' : { "version = 1.${it}" },
'docs/source/conf.py' : { "version = '1.${it}'" },
'docs/source/getting-started.rst' : [{ "<version>1.${it}</version>" }, {
"wiremock/1.${it}/wiremock-1.${it}-standalone.jar"
}],
'docs/source/running-standalone.rst': { "wiremock/1.${it}/wiremock-1.${it}-standalone.jar" },
'sample-war/build.gradle' : { "com.github.tomakehurst:wiremock:1.${it}" },
]
def gradleBuildFile = new File('build.gradle')
int currentMinorVersion
gradleBuildFile.text.find ~/version = 1.([0-9]+)/, { match, minorVersion ->
currentMinorVersion = Integer.valueOf(minorVersion)
int nextMinorVersion = currentMinorVersion - 1
filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = new File(fileName)
def lineWithVersionTemplateList = lineWithVersionTemplates instanceof List ?
lineWithVersionTemplates :
[lineWithVersionTemplates];
lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentMinorVersion)
def newLine = lineWithVersionTemplate.call(nextMinorVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine);
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.5'
}
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;
}
}
}