forked from ratpack/ratpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratpack.gradle
362 lines (306 loc) · 10.3 KB
/
ratpack.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
/*
* Copyright 2013 the original author or authors.
*
* 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.
*/
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.ReentrantLock
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:2.2.3"
// Artifactory plugin pulls in very old Guava, which conflicts with child projects.
// Force to newer version here.
classpath 'com.google.guava:guava:18.0'
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
classpath "com.github.ben-manes:gradle-versions-plugin:0.8"
}
}
def jvmEncoding = java.nio.charset.Charset.defaultCharset().name()
if (jvmEncoding != "UTF-8") {
throw new IllegalStateException("Build environment must be UTF-8 (it is: $jvmEncoding) - add '-Dfile.encoding=UTF-8' to the GRADLE_OPTS environment variable ")
}
if (!JavaVersion.current().java8Compatible) {
throw new IllegalStateException("Must be built with Java 8 or higher")
}
apply plugin: "artifactory"
apply plugin: "com.github.kt3k.coveralls"
apply plugin: "com.github.ben-manes.versions"
artifactory {
contextUrl = 'http://oss.jfrog.org'
}
artifactoryPublish {
skip true
}
task bintrayPublish << {
if (!(ratpackBintrayUser && ratpackBintrayApiKey)) {
throw new InvalidUserDataException("You must provide ratpackBintrayUser and ratpackBintrayApiKey")
}
if (!project.hasProperty('buildNumber')) {
throw new GradleException("Must provide buildNumber of a release binary from oss.jfrog.org")
}
def baseUrl = 'https://oss.jfrog.org/api/plugins/build/promote/releaseToBintray/ratpack/'
def params = '?params=org=ratpack|repo=maven|package=ratpack'
def curlUrl = [baseUrl, project.buildNumber, params].join('')
def curl = ['curl', '-X', 'POST', '-u',
/"${ratpackBintrayUser}:${ratpackBintrayApiKey}"/, curlUrl].execute()
logger.info("Received response: ${curl.text}")
}
task gradlePluginPortalPublish << {
def packages = ['ratpack-java', 'ratpack-groovy']
packages.each { bintrayPackage ->
def bintraySubject = 'ratpack'
def bintrayRepo = 'gradle-plugins-meta'
def version = project.version
def parts = "$bintraySubject/$bintrayRepo/$bintrayPackage"
def baseUrl = 'https://api.bintray.com'
def createUrl = "$baseUrl/packages/$parts/versions"
logger.info("Creating new version")
exec {
executable = 'curl'
args = ['-H', '"Content-Type: application/json"', '-X', 'POST', '-d', /{\"name\":\"$version\"}/,
'-u', /"${ratpackBintrayUser}:${ratpackBintrayApiKey}"/, createUrl]
}
def attributeUrl = "$baseUrl/packages/$parts/versions/$version/attributes"
logger.info("Creating attributes")
exec {
executable = 'curl'
args = ['-H', '"Content-Type: application/json"', '-X', 'POST', '-d', /[{\"name\":\"gradle-plugin\",\"values\":[\"io.ratpack.$bintrayPackage:io.ratpack:ratpack-gradle\"]}]/,
'-u', /"${ratpackBintrayUser}:${ratpackBintrayApiKey}"/, attributeUrl]
}
def f = File.createTempFile("$bintrayPackage-$version", ".txt")
f.write('This is a placeholder file.')
f.deleteOnExit()
def uploadUrl = "$baseUrl/content/$parts/$version/${bintrayPackage}-${version}.txt"
logger.info("Uploading file")
exec {
executable = 'curl'
args = ['-T', f.absolutePath, '-u', /"${ratpackBintrayUser}:${ratpackBintrayApiKey}"/, uploadUrl]
}
def publishUrl = "$baseUrl/content/$parts/$version/publish"
logger.info("Publishing")
exec {
executable = 'curl'
args = ['-X', 'POST', '-u', /"${ratpackBintrayUser}:${ratpackBintrayApiKey}"/, publishUrl]
}
}
}
allprojects {
group = "io.ratpack"
version = "0.9.16-SNAPSHOT"
apply plugin: "base"
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "java"
apply plugin: "jacoco"
apply from: "$rootDir/gradle/dependencyRules.gradle"
repositories {
jcenter()
maven { url 'http://oss.jfrog.org/artifactory/repo' }
}
jacoco {
toolVersion = "0.7.2.201409121644"
}
}
apply from: "gradle/idea/idea.gradle"
ext {
isSnapshot = version.endsWith("SNAPSHOT")
isTravis = System.getenv("TRAVIS") != null
isDrone = System.getenv("DRONE") != null
isCodeship = System.getenv("CI_NAME") == "codeship"
isSnapCi = System.getenv("SNAP_CI") != null
isAppveyor = System.getenv("APPVEYOR") != null
isCloudCi = isTravis || isDrone || isCodeship || isSnapCi || isAppveyor
isHeroku = System.getenv("HEROKU") != null
publishedModules = [
"ratpack-core", "ratpack-groovy", "ratpack-guice", "ratpack-session", "ratpack-test", "ratpack-groovy-test",
"ratpack-manual", "ratpack-gradle", "ratpack-handlebars", "ratpack-remote", "ratpack-remote-test", "ratpack-jackson",
"ratpack-codahale-metrics", "ratpack-h2", "ratpack-thymeleaf", "ratpack-rx", "ratpack-hikari", "ratpack-newrelic",
"ratpack-pac4j", "ratpack-hystrix", "ratpack-spring-boot", "ratpack-config"
].collect { project(it) }
apiModules = publishedModules.findAll { !(it.name in ["ratpack-manual", "ratpack-gradle"]) }
localRepoUrl = "${buildDir.toURI()}/localrepo"
}
apply from: "gradle/dependencies.gradle"
subprojects {
tasks.withType(Upload).matching { it.name != "install" }.all {
rootProject.subprojects {
mustRunAfter tasks.matching { it instanceof VerificationTask }
}
}
// CodeNarc appears to hang in drone.io
tasks.withType(CodeNarc) {
onlyIf { !rootProject.hasProperty("ciBuild") }
}
tasks.withType(Test) {
allprojects {
mustRunAfter tasks.withType(Checkstyle)
}
}
tasks.withType(GroovyCompile) {
allprojects {
mustRunAfter tasks.withType(CodeNarc)
}
}
apply from: "$rootDir/gradle/ratpackLocal.gradle"
tasks.withType(Javadoc) {
options.encoding = "utf-8"
options.docEncoding = "utf-8"
options.charSet = "utf-8"
exclude "**/internal/**"
}
apply plugin: "maven"
apply from: "${rootDir}/gradle/pom.gradle"
apply plugin: "signing"
if (rootProject.hasProperty("ciBuild")) {
plugins.withType(ReportingBasePlugin) {
reporting.baseDir = rootProject.file("build/reports/$name")
}
}
jacocoTestReport {
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
classDirectories = files(sourceSets.main.output)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
// Have to evaluate the children before setting up the publishing stuff so the dependencies are defined.
evaluationDependsOnChildren()
subprojects {
configurations.signatures.artifacts.all {
extension = toSignArtifact.extension + "." + extension
}
if (project in publishedModules) {
apply plugin: "artifactory"
artifactoryPublish { task ->
rootProject.artifactory {
publish {
repository {
repoKey = isSnapshot ? 'oss-snapshot-local' : 'oss-release-local'
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(task)) {
username = ratpackBintrayUser
password = ratpackBintrayApiKey
}
}
}
}
}
}
assert description: "Project $project.path is published, must have a description"
modifyPom {
project {
name project.name
description project.description
url "http://www.ratpack.io"
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
scm {
connection "scm:https://[email protected]/ratpack/ratpack"
developerConnection "scm:[email protected]:ratpack/ratpack.git"
url "https://github.com/ratpack/ratpack"
}
developers {
developer {
id "ratpack"
name "Team Ratpack"
}
}
}
}
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "failed"
}
jvmArgs "-Xss320k"
minHeapSize "312m"
maxHeapSize "312m"
doFirst {
if (isCloudCi) {
maxParallelForks 1
}
}
}
}
task ciZip(type: Zip) {
into "reports", { from "build/reports" }
into "manual", { from { project(":ratpack-manual").packageManual } }
archiveName = "ci.zip"
destinationDir = buildDir
}
task stage {
dependsOn "clean", ":ratpack-site:installApp"
}
task jacocoReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn publishedModules.test
sourceDirectories = files(publishedModules.sourceSets.main.allSource.srcDirs)
classDirectories = files(publishedModules.sourceSets.main.output)
executionData = files(publishedModules.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
coveralls {
service = System.getenv().get("CI_NAME")
sourceDirs = jacocoReport.sourceDirectories.files.toList()
jacocoReportPath = jacocoReport.reports.xml.destination.absolutePath - rootDir.absolutePath
}
task testReport(type: TestReport) {
destinationDir file("$buildDir/tests")
reportOn subprojects.collect { it.tasks.test }
}
task allDependencies << {
allprojects { p ->
configurations.each { c ->
println "Downloading dependencies for $p.path - $c.name"
c.files
}
}
}
// Maven POM generation is not thread safe, so serialize all the Upload tasks we can use `--parallel`.
def lock = new ReentrantLock()
def available = lock.newCondition()
def busy = new AtomicBoolean()
allprojects {
tasks.withType(Upload) { uploadTask ->
doFirst {
lock.lock()
while (busy.get()) {
available.await()
}
busy.set(true)
}
}
}
gradle.taskGraph.afterTask {
if (it instanceof Upload && lock.heldByCurrentThread) {
busy.set(false)
available.signal()
lock.unlock()
}
}