blob: ca18d6c3b998321bc64e3806ad885b1ceabc99a8 [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
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}"
}
}
}
}
/* 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 "com.sun.jersey.contribs:jersey-guice:${jerseyRev}"
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 "commons-lang:commons-lang:${commonsLangRev}"
compile "javax.servlet:servlet-api:${servletRev}"
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}"
testCompile "com.sun.jersey:jersey-client:${jerseyRev}"
}
}
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 {
jdkName = '1.8'
[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.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.11.2'
}
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'
}
}
// 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}:")
}
}