forked from apache/aurora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
553 lines (483 loc) · 16.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
553
/*
* 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 org.apache.aurora.build.CoverageReportCheck
import org.gradle.api.JavaVersion
plugins {
id 'com.eriwen.gradle.js' version '1.12.1'
id 'com.github.ben-manes.versions' version '0.10.1'
id 'com.github.hierynomus.license' version '0.11.0'
id 'me.champeau.gradle.jmh' version '0.2.0'
}
apply plugin: 'application'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
apply plugin: 'pmd'
def minJavaVersion = JavaVersion.VERSION_1_8;
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'project-report'
buildDir = 'dist'
repositories {
mavenCentral()
}
compileJava {
sourceCompatibility = minJavaVersion
targetCompatibility = minJavaVersion
}
group 'org.apache.aurora'
version = file("${rootDir}/.auroraversion").text.trim().toUpperCase()
if (version.contains('/')) {
throw new GradleException('''
*******************************************************************************
The application version string read by gradle is invalid. This is known to
happen when building on Windows, or within vagrant with a Windows host.
You can work around this issue by cloning git _within_ vagrant and building
from there.
For more details, please see https://issues.apache.org/jira/browse/AURORA-1169
*******************************************************************************
''')
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
if (project.hasProperty('internalMavenUrl')) {
publishing {
repositories {
maven {
credentials {
username = internalMavenUser
password = internalMavenPass
}
url internalMavenUrl
}
}
}
}
ext.junitRev = '4.12'
ext.log4jRev = '1.2.17'
ext.gsonRev = '2.3.1'
ext.guavaRev = '18.0'
ext.slf4jRev = '1.7.12'
ext.thriftRev = '0.9.1'
ext.guiceRev = '3.0'
ext.servletRev = '2.5'
ext.stringTemplateRev = '3.2.1'
ext.zookeeperRev = '3.3.4'
ext.jerseyRev = '1.18.1'
ext.jsrRev = '2.0.1'
ext.commonsLangRev = '2.6'
configurations {
compile {
exclude module: 'junit-dep'
// ResolutionStrategy needs to be set in the allprojects block otherwise dependent projects
// will not inherit it. Note that dependencies still need to be specified in a dependencies
// block - this only affects strategy.
// See http://forums.gradle.org/gradle/topics/shouldnt-resolutionstrategy-affect-depending-projects-transitive-dependencies
resolutionStrategy {
failOnVersionConflict()
force "org.slf4j:slf4j-api:${slf4jRev}"
force "com.google.code.gson:gson:${gsonRev}"
force "log4j:log4j:${log4jRev}"
force "junit:junit:${junitRev}"
// Force versions based on inter-dependency collisions
force "org.hamcrest:hamcrest-core:1.3"
force "org.apache.thrift:libthrift:${thriftRev}"
force "org.slf4j:slf4j-jdk14:${slf4jRev}"
force 'com.fasterxml.jackson.core:jackson-annotations:2.5.1'
force 'com.fasterxml.jackson.core:jackson-core:2.5.1'
}
}
}
}
/* This gradle project contains the annotation procesor from
* com.twitter.common.args and related dependencies. It needs to be outside of
* the commons project because gradle needs to compile the annotation processor
* first.
*/
project(':commons-args') {
dependencies {
compile "com.google.guava:guava:${guavaRev}"
compile "com.google.code.findbugs:jsr305:${jsrRev}"
compile "commons-lang:commons-lang:${commonsLangRev}"
}
apply plugin: 'license'
license {
header rootProject.file('config/checkstyle/apache.header')
strictCheck true
}
}
project(':commons') {
apply plugin: org.apache.aurora.build.ThriftPlugin
thrift {
version = thriftRev
}
apply plugin: 'license'
license {
header rootProject.file('config/checkstyle/apache.header')
strictCheck true
}
dependencies {
compile project(':commons-args')
compile "com.google.code.findbugs:jsr305:${jsrRev}"
compile "com.google.code.gson:gson:${gsonRev}"
compile "com.google.guava:guava:${guavaRev}"
compile "com.google.inject.extensions:guice-multibindings:${guiceRev}"
compile "com.google.inject:guice:${guiceRev}"
compile "commons-lang:commons-lang:${commonsLangRev}"
compile "javax.servlet:servlet-api:${servletRev}"
compile "javax.ws.rs:javax.ws.rs-api:2.0.1"
compile "joda-time:joda-time:2.3"
compile "log4j:log4j:${log4jRev}"
compile "org.antlr:stringtemplate:${stringTemplateRev}"
compile "org.apache.zookeeper:zookeeper:${zookeeperRev}"
compile "org.easymock:easymock:3.2"
compile "org.slf4j:slf4j-jdk14:${slf4jRev}"
testCompile "junit:junit:${junitRev}"
}
}
project(':api') {
apply plugin: org.apache.aurora.build.ThriftPlugin
apply plugin: org.apache.aurora.build.ThriftEntitiesPlugin
task checkPython << {
def python27Executable = ['python2.7', 'python'].find { python ->
try {
def check = "import sys; sys.exit(0 if sys.version_info >= (2,7) and sys.version_info < (3,) else 1)"
return [python, "-c", check].execute().waitFor() == 0
} catch (IOException e) {
return false
}
}
if (python27Executable == null) {
throw new GradleException('Build requires Python 2.7.')
} else {
thriftEntities.python = python27Executable
}
}
generateThriftEntitiesJava.dependsOn checkPython
tasks.withType(Jar) {
baseName "aurora-api"
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifactId "aurora-api"
artifact sourceJar {
classifier "sources"
}
}
}
}
thrift {
version = thriftRev
resourcePrefix = 'org/apache/aurora/scheduler/gen/client'
}
thriftEntities {
gsonRev = project.gsonRev
guavaRev = project.guavaRev
inputFiles = fileTree("src/main/thrift/org/apache/aurora/gen").matching {
include "**/*.thrift"
}
}
idea {
module {
[thrift.genJavaDir, thriftEntities.genJavaDir].each {
sourceDirs += it
generatedSourceDirs += it
}
scopes.COMPILE.plus += [parent.configurations.jmh]
// These directories must exist, else the plugin omits them from the
// generated project. Since this is executed during the configuration
// lifecycle phase, dependency tasks have not yet run and created
// the directories themselves.
// By default, the idea module [1] excludes are set to
// [project.buildDir, project.file('.gradle')]
// This has the side-effect of also excluding our generated sources [2]. Due to the way
// directory exclusion works in idea, you can't exclude a directory and include a child of that
// directory. Clearing the excludes seems to have no ill side-effects, making it preferable to
// other possible approaches.
//
// [1] http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
// [2] http://issues.gradle.org/browse/GRADLE-1174
excludeDirs = [file(".gradle")]
[
"classes",
"dependency-cache",
"docs",
"jacoco",
"reports",
"test-results",
"tmp"
].each {
excludeDirs << file("$buildDir/$it")
}
}
}
}
def generatedDir = "$buildDir/generated-src"
def httpAssetsPath = 'scheduler/assets'
compileJava {
options.compilerArgs << '-Werror'
options.compilerArgs << '-Xlint:all'
// Don't fail for annotations not claimed by annotation processors.
options.compilerArgs << '-Xlint:-processing'
// Don't fail for serialVersionUID warnings.
options.compilerArgs << '-Xlint:-serial'
}
task enforceVersion {
def foundVersion = JavaVersion.current();
if (foundVersion < minJavaVersion) {
throw new GradleException("Build requires at least Java ${minJavaVersion}; but ${foundVersion}"
+ " was found. Consider setting JAVA_HOME to select a specific JDK on your system.");
}
}
compileJava.dependsOn(enforceVersion);
task wrapper(type: Wrapper) {
gradleVersion = project(':buildSrc').GRADLE_VERSION
}
// TODO(ksweeney): Consider pushing this down to API - the scheduler implementation itself should
// only be consumed as an application.
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifactId 'aurora-scheduler'
artifact sourceJar {
classifier "sources"
}
}
}
}
task generateBuildProperties (type:Exec) {
def outputDir = file("${buildDir}/build-properties")
def outputFile = file("${outputDir}/build.properties")
inputs.dir rootDir
outputs.dir outputDir
doFirst {
outputDir.exists() || outputDir.mkdirs()
}
commandLine "${projectDir}/build-support/generate-build-properties", "${outputFile}"
}
sourceSets {
main {
output.dir generateBuildProperties
resources {
srcDir '3rdparty/javascript'
}
}
}
dependencies {
def shiroRev = '1.2.4'
def gsonDep = "com.google.code.gson:gson:${gsonRev}"
def guavaDep = "com.google.guava:guava:${guavaRev}"
// NOTE: We are using the jetty 7.x series due to a large number of dependencies impacted
// by 8.x and later resulting from using newer javax.servlet servlet-api.
def jettyDep = '7.6.15.v20140411'
compile project(':api')
compile project(':commons')
compile 'aopalliance:aopalliance:1.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile "com.google.inject:guice:${guiceRev}"
compile "com.google.inject.extensions:guice-assistedinject:${guiceRev}"
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.h2database:h2:1.4.187'
compile 'com.hubspot.jackson:jackson-datatype-protobuf:0.9.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.1'
compile "com.sun.jersey:jersey-core:${jerseyRev}"
compile "com.sun.jersey:jersey-json:${jerseyRev}"
compile "com.sun.jersey:jersey-server:${jerseyRev}"
compile "com.sun.jersey:jersey-servlet:${jerseyRev}"
compile "com.sun.jersey.contribs:jersey-guice:${jerseyRev}"
compile 'javax.inject:javax.inject:1'
compile "javax.servlet:servlet-api:${servletRev}"
compile "log4j:log4j:${log4jRev}"
compile "org.antlr:stringtemplate:${stringTemplateRev}"
compile 'org.apache.mesos:mesos:0.23.0'
compile("org.apache.shiro:shiro-guice:${shiroRev}")
compile "org.apache.shiro:shiro-web:${shiroRev}"
compile "org.apache.zookeeper:zookeeper:${zookeeperRev}"
compile "org.eclipse.jetty:jetty-rewrite:${jettyDep}"
compile "org.eclipse.jetty:jetty-server:${jettyDep}"
compile "org.eclipse.jetty:jetty-servlet:${jettyDep}"
compile "org.eclipse.jetty:jetty-servlets:${jettyDep}"
compile 'org.mybatis:mybatis:3.3.0'
compile 'org.mybatis:mybatis-guice:3.6'
compile 'org.quartz-scheduler:quartz:2.2.1'
compile "org.slf4j:slf4j-jdk14:${slf4jRev}"
testCompile "com.sun.jersey:jersey-client:${jerseyRev}"
testCompile "junit:junit:${junitRev}"
configurations.compile {
}
}
// For normal developer builds, avoid running the often-time-consuming code quality checks.
// Jenkins will always run these, and developers are encouraged to run these before posting diffs
// and pushing to master.
def runCodeQuality = project.hasProperty('q')
def codeQualityTasks = [
Checkstyle,
FindBugs,
nl.javadude.gradle.plugins.license.License,
Pmd
]
codeQualityTasks.each {
tasks.withType(it) {
enabled = runCodeQuality
}
}
checkstyle {
sourceSets = [sourceSets.main , sourceSets.test, sourceSets.jmh]
toolVersion = '6.12.1'
}
findbugs {
toolVersion = '3.0.1'
effort = "max"
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
maxHeapSize = '1g'
excludeFilter = rootProject.file('config/findbugs/excludeFilter.xml')
}
pmd {
// Avoiding gradle's upgrade of PMD since there have been regressions in some rules post-5.1.1.
// For example, UnusedPrivateMethod raises some obvious false positives.
toolVersion = '5.1.1'
sourceSets = [sourceSets.main]
// PMD rule set names match XML files stored in the PMD jar. For example, with 5.11 you can
// see all the rules included with:
// $ find ~/.gradle -name pmd-5.1.1.jar | xargs zipinfo -1 | egrep java/.*.xml | head -n 5
// rulesets/java/clone.xml
// rulesets/java/basic.xml
// rulesets/java/strings.xml
// rulesets/java/sunsecure.xml
// rulesets/java/codesize.xml
// The format is straightforward: 'java-basic' refers to rulesets/java/basic.xml.
ruleSets = [
'java-braces',
'java-junit',
'java-typeresolution',
'java-unnecessary',
'java-unusedcode']
ruleSetFiles = fileTree('config/pmd/')
consoleOutput = true
}
/**
* There is a jshint target recommended in the README for gradle-js-plugin
* but it does not work. This workaround from here:
* https://github.com/eriwen/gradle-js-plugin/issues/73
*/
task jsHint(type:com.eriwen.gradle.js.tasks.JsHintTask) {
source = fileTree("src/main/resources/$httpAssetsPath/js/")
dest file("${buildDir}/jshint.out")
// Set this to false once JS code complies with JSHint.
ignoreExitCode false
outputToStdOut true
jshint.options = [
// See: http://www.jshint.com/docs/options/ for explanation.
browser: true,
camelcase: true,
curly: true,
eqeqeq: true,
indent: 2,
maxlen: 100,
quotmark: true,
trailing: true,
undef: true,
unused: 'vars',
white: true
]
jshint.predef = [
'_': true,
'angular': true,
'moment': true,
'Thrift': true
]
}
tasks.checkstyleMain.dependsOn(jsHint)
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors()
}
idea {
project {
vcs = 'Git'
jdkName = '1.8'
languageLevel = '1.8'
}
}
// Configuration parameters for the application plugin.
applicationName = 'aurora-scheduler'
mainClassName = 'org.apache.aurora.scheduler.app.SchedulerMain'
// TODO(ksweeney): Configure this to scan resources as well.
tasks.withType(nl.javadude.gradle.plugins.license.License).each {
it.source = files("$projectDir/src/main/java", "$projectDir/src/test/java")
}
license {
header rootProject.file('config/checkstyle/apache.header')
strictCheck true
skipExistingHeaders true
}
def reportPath = "$buildDir/reports/jacoco/test"
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
sourceDirectories = sourceSets.main.java
classDirectories = files("$buildDir/classes/main")
reports {
xml.enabled true
}
doLast {
println "Coverage report generated: file://$reportPath/html/index.html"
}
}
test.finalizedBy jacocoTestReport
task analyzeReport(type: CoverageReportCheck) {
coverageReportFile = "$reportPath/jacocoTestReport.xml"
minInstructionCoverage = 0.89
minBranchCoverage = 0.835
legacyClassesWithoutCoverage = file('config/legacy_untested_classes.txt').readLines()
}
jacocoTestReport.finalizedBy analyzeReport
def jmhHumanOutputPath = "$buildDir/reports/jmh/human.txt"
jmh {
// Run specific benchmarks by passing -Pbenchmarks='<regexp' on the command line. For example
// ./gradlew jmh -Pbenchmarks='ThriftApi.*'
if (project.hasProperty('benchmarks')) {
include = project.getProperty('benchmarks')
}
jmhVersion = '1.7.1'
jvmArgsPrepend = '-Xmx3g'
humanOutputFile = project.file("$jmhHumanOutputPath")
resultsFile = project.file("$buildDir/reports/jmh/results.txt")
}
tasks.getByName('jmh').doLast() {
println "Benchmark report generated: file://$jmhHumanOutputPath"
}
run {
main = 'org.apache.aurora.scheduler.app.local.LocalSchedulerMain'
classpath += sourceSets.test.output
}
startScripts {
def environmentClasspathPrefix = System.env.CLASSPATH_PREFIX
if (!environmentClasspathPrefix?.trim()) {
return
}
doLast {
unixScript.text = unixScript.text.replace('CLASSPATH=', "CLASSPATH=${environmentClasspathPrefix}:")
}
}