blob: f9f71a84493b782e9f6072e44e89a2c017cf2a09 [file] [log] [blame]
/*
* 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
plugins {
id 'com.eriwen.gradle.js' version '1.12.1'
id 'com.github.ben-manes.versions' version '0.5'
id 'com.github.hierynomus.license' version '0.11.0'
id 'me.champeau.gradle.jmh' version '0.1.3'
}
apply plugin: 'application'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
apply plugin: 'pmd'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'project-report'
buildDir = 'dist'
repositories {
mavenCentral()
maven {
url 'http://maven.twttr.com/'
}
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
group 'org.apache.aurora'
version = file("${rootDir}/.auroraversion").text.trim().toUpperCase()
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.11'
ext.log4jRev = '1.2.17'
ext.gsonRev = '2.2.4'
ext.guavaRev = '16.0'
ext.slf4jRev = '1.6.6'
ext.thriftRev = '0.9.1'
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}"
}
}
}
}
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 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"
}
}
}
}
sourceSets {
main {
resources {
srcDir '3rdparty/javascript'
}
}
}
dependencies {
def guiceRev = '3.0'
def jerseyRev = '1.18.1'
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 '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.177'
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:2.5'
compile "log4j:log4j:${log4jRev}"
compile 'org.antlr:stringtemplate:3.2.1'
compile 'org.apache.mesos:mesos:0.20.1'
compile 'org.apache.zookeeper:zookeeper:3.3.4'
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.2.7'
compile 'org.mybatis:mybatis-guice:3.6'
compile 'org.quartz-scheduler:quartz:2.2.1'
compile "org.slf4j:slf4j-jdk14:${slf4jRev}"
compile 'com.twitter.common.logging:log4j:0.0.7'
compile 'com.twitter.common.zookeeper.guice:client-flagged:0.0.5'
compile 'com.twitter.common.zookeeper.guice:client:0.0.5'
compile 'com.twitter.common.zookeeper:candidate:0.0.64'
compile 'com.twitter.common.zookeeper:client:0.0.56'
compile 'com.twitter.common.zookeeper:group:0.0.69'
compile 'com.twitter.common.zookeeper:server-set:1.0.74'
compile 'com.twitter.common.zookeeper:singleton-service:0.0.85'
compile 'com.twitter.common:application-module-applauncher:0.0.51'
compile 'com.twitter.common:application-module-lifecycle:0.0.48'
compile 'com.twitter.common:application-module-stats:0.0.44'
compile 'com.twitter.common:application:0.0.73'
compile 'com.twitter.common:args:0.2.9'
compile 'com.twitter.common:base:0.0.87'
compile 'com.twitter.common:collections:0.0.74'
compile 'com.twitter.common:dynamic-host-set:0.0.44'
compile 'com.twitter.common:inject-timed:0.0.11'
compile 'com.twitter.common:inject:0.0.35'
compile 'com.twitter.common:jdk-logging:0.0.44'
compile 'com.twitter.common:logging:0.0.61'
compile 'com.twitter.common:net-http-handlers-time-series:0.0.51'
compile 'com.twitter.common:net-util:0.0.80'
compile 'com.twitter.common:quantity:0.0.71'
compile 'com.twitter.common:stats:0.0.91'
compile 'com.twitter.common:thrift:0.0.68'
compile 'com.twitter.common:util-executor-service-shutdown:0.0.49'
compile 'com.twitter.common:util-templating:0.0.25'
compile 'com.twitter.common:util-testing:0.0.10'
compile 'com.twitter.common:util:0.0.94'
testCompile "com.sun.jersey:jersey-client:${jerseyRev}"
testCompile 'com.twitter.common:testing-easymock:0.0.4'
testCompile 'com.twitter.common:util-system-mocks:0.0.72'
testCompile 'com.twitter.common:zookeeper-testing:0.0.45'
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]
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
excludeFilter = rootProject.file('config/findbugs/excludeFilter.xml')
}
pmd {
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-basic',
'java-braces',
'java-empty',
'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'
}
}
// 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 {
humanOutputFile = project.file("$jmhHumanOutputPath")
resultsFile = project.file("$buildDir/reports/jmh/results.txt")
// JMH run configuration parameters.
iterations = 3
fork = 1
warmupIterations = 1
}
tasks.getByName('jmh').doLast() {
println "Benchmark report generated: file://$jmhHumanOutputPath"
}
run {
main = 'org.apache.aurora.scheduler.app.local.LocalSchedulerMain'
classpath += sourceSets.test.output
}