blob: 2e79333f061e0b0c33a1d65c8957979f394ae675 [file] [log] [blame]
buildscript {
repositories {
mavenCentral()
mavenLocal()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.6'
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.16'
classpath "net.ltgt.gradle:gradle-apt-plugin:0.18"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.8"
classpath "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.0"
}
}
// Display the version report using: ./gradlew dependencyUpdates
// Also see https://github.com/ben-manes/gradle-versions-plugin.
apply plugin: 'com.github.ben-manes.versions'
subprojects {
// OC-Agent exporter depends on grpc-core which depends on errorprone annotations, and it
// doesn't work with checker framework.
def projectsDependOnGrpcCore = ["opencensus-exporter-metrics-ocagent", "opencensus-exporter-trace-ocagent"]
// Don't use the Checker Framework by default, since it interferes with Error Prone.
def useCheckerFramework = rootProject.hasProperty('checkerFramework') && !(project.name in projectsDependOnGrpcCore)
def useErrorProne = !useCheckerFramework
apply plugin: "checkstyle"
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: "signing"
apply plugin: "jacoco"
// The plugin only has an effect if a signature is specified
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'findbugs'
apply plugin: 'net.ltgt.apt'
apply plugin: 'net.ltgt.apt-idea'
apply plugin: "me.champeau.gradle.jmh"
apply plugin: "io.morethan.jmhreport"
apply plugin: 'com.github.sherter.google-java-format'
if (useErrorProne) {
apply plugin: "net.ltgt.errorprone"
}
group = "io.opencensus"
version = "0.32.0-SNAPSHOT" // CURRENT_OPENCENSUS_VERSION
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
mavenLocal()
}
if (useCheckerFramework) {
configurations {
checkerFrameworkJavac {
description = 'a customization of the Open JDK javac compiler with additional support for type annotations'
}
checkerFrameworkAnnotatedJDK {
description = 'a copy of JDK classes with Checker Framework type qualifiers inserted'
}
}
}
[compileJava, compileTestJava, compileJmhJava].each() {
// We suppress the "try" warning because it disallows managing an auto-closeable with
// try-with-resources without referencing the auto-closeable within the try block.
// We suppress the "processing" warning as suggested in
// https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM
it.options.compilerArgs += ["-Xlint:all", "-Xlint:-try", "-Xlint:-processing"]
if (useErrorProne) {
it.options.compilerArgs += ["-XepAllDisabledChecksAsWarnings", "-XepDisableWarningsInGeneratedCode"]
// -XepDisableWarningsInGeneratedCode doesn't suppress all warnings in generated
// protocol buffer code.
it.options.compilerArgs += ["-XepExcludedPaths:.*/gen_gradle/.*"]
// MutableMethodReturnType can suggest returning Guava types from
// API methods (https://github.com/google/error-prone/issues/982).
it.options.compilerArgs += ["-Xep:MutableMethodReturnType:OFF"]
// ReturnMissingNullable conflicts with Checker Framework null analysis.
it.options.compilerArgs += ["-Xep:ReturnMissingNullable:OFF"]
// OpenCensus doesn't currently use Var annotations.
it.options.compilerArgs += ["-Xep:Var:OFF"]
// ImmutableRefactoring suggests using com.google.errorprone.annotations.Immutable,
// but OpenCensus currently uses javax.annotation.concurrent.Immutable
it.options.compilerArgs += ["-Xep:ImmutableRefactoring:OFF"]
// This check causes a NullPointerException
// (https://github.com/google/error-prone/issues/1138).
it.options.compilerArgs += ["-Xep:NullableDereference:OFF"]
// ExpectedExceptionRefactoring and TestExceptionRefactoring suggest using
// assertThrows, but assertThrows only works well with lambdas.
it.options.compilerArgs += ["-Xep:ExpectedExceptionRefactoring:OFF"]
it.options.compilerArgs += ["-Xep:TestExceptionRefactoring:OFF"]
}
if (useCheckerFramework) {
it.options.compilerArgs += [
'-processor',
'com.google.auto.value.processor.AutoValueProcessor,org.checkerframework.checker.nullness.NullnessChecker',
"-Astubs=$rootDir/checker-framework/stubs"
]
}
it.options.encoding = "UTF-8"
// Protobuf-generated code produces some warnings.
// https://github.com/google/protobuf/issues/2718
it.options.compilerArgs += ["-Xlint:-cast"]
if (!JavaVersion.current().isJava9() && !useErrorProne) {
// TODO(sebright): Enable -Werror for Java 9 once we upgrade AutoValue (issue #1017).
it.options.compilerArgs += ["-Werror"]
}
if (JavaVersion.current().isJava9()) {
// TODO(sebright): Currently, building with Java 9 produces the following "options" warnings:
//
// :opencensus-api:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.6
// warning: [options] source value 1.6 is obsolete and will be removed in a future release
// warning: [options] target value 1.6 is obsolete and will be removed in a future release
it.options.compilerArgs += ["-Xlint:-options"]
}
}
compileTestJava {
// serialVersionUID is basically guaranteed to be useless in tests
options.compilerArgs += ["-Xlint:-serial"]
// It undeprecates DoubleSubject.isEqualTo(Double).
options.compilerArgs += ["-Xlint:-deprecation"]
}
jar.manifest {
attributes('Implementation-Title': name,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-JDK': System.getProperty('java.version'),
'Source-Compatibility': sourceCompatibility,
'Target-Compatibility': targetCompatibility)
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/8/docs/api/'
}
ext {
appengineVersion = '1.9.71'
aspectjVersion = '1.8.11'
autoValueVersion = '1.4'
findBugsAnnotationsVersion = '3.0.1'
findBugsJsr305Version = '3.0.2'
errorProneVersion = '2.3.2'
grpcVersion = '1.27.2'
guavaVersion = '29.0-android'
googleAuthVersion = '0.20.0'
googleCloudBetaVersion = '0.100.0-beta'
googleCloudGaVersion = '1.82.0'
log4j2Version = '2.16.0'
signalfxVersion = '0.0.48'
springBoot2Version = '2.1.5.RELEASE'
springBootVersion = '1.5.15.RELEASE'
springBootTestVersion = '2.1.1.RELEASE'
springCloudVersion = '1.3.4.RELEASE'
springVersion = '4.3.12.RELEASE'
prometheusVersion = '0.6.0'
protobufVersion = '3.11.4'
zipkinReporterVersion = '2.7.14'
jaegerReporterVersion = '0.33.1'
opencensusProtoVersion = '0.2.0'
gsonVersion = '2.8.6'
dropwizardVersion = '3.1.2'
dropwizard5Version = '5.0.0'
javaxServletVersion = "3.1.0"
httpcomponentsVersion = "4.5.8"
libraries = [
appengine_api: "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}",
aspectj: "org.aspectj:aspectjrt:${aspectjVersion}",
auto_value: "com.google.auto.value:auto-value:${autoValueVersion}",
auto_service: 'com.google.auto.service:auto-service:1.0-rc3',
byte_buddy: 'net.bytebuddy:byte-buddy:1.8.22',
config: 'com.typesafe:config:1.2.1',
disruptor: 'com.lmax:disruptor:3.4.2',
errorprone: "com.google.errorprone:error_prone_annotations:${errorProneVersion}",
findbugs_annotations: "com.google.code.findbugs:annotations:${findBugsAnnotationsVersion}",
google_auth: "com.google.auth:google-auth-library-credentials:${googleAuthVersion}",
google_cloud_logging: "com.google.cloud:google-cloud-logging:${googleCloudGaVersion}",
google_cloud_trace: "com.google.cloud:google-cloud-trace:${googleCloudBetaVersion}",
log4j2: "org.apache.logging.log4j:log4j-core:${log4j2Version}",
zipkin_reporter: "io.zipkin.reporter2:zipkin-reporter:${zipkinReporterVersion}",
zipkin_urlconnection: "io.zipkin.reporter2:zipkin-sender-urlconnection:${zipkinReporterVersion}",
jaeger_reporter: "io.jaegertracing:jaeger-client:${jaegerReporterVersion}",
google_cloud_monitoring: "com.google.cloud:google-cloud-monitoring:${googleCloudGaVersion}",
grpc_auth: "io.grpc:grpc-auth:${grpcVersion}",
grpc_context: "io.grpc:grpc-context:${grpcVersion}",
grpc_core: "io.grpc:grpc-core:${grpcVersion}",
grpc_netty: "io.grpc:grpc-netty:${grpcVersion}",
grpc_netty_shaded: "io.grpc:grpc-netty-shaded:${grpcVersion}",
grpc_stub: "io.grpc:grpc-stub:${grpcVersion}",
guava: "com.google.guava:guava:${guavaVersion}",
jsr305: "com.google.code.findbugs:jsr305:${findBugsJsr305Version}",
signalfx_java: "com.signalfx.public:signalfx-java:${signalfxVersion}",
spring_aspects: "org.springframework:spring-aspects:${springVersion}",
spring_boot_starter_web: "org.springframework.boot:spring-boot-starter-web:${springBootVersion}",
spring_boot_starter_web2: "org.springframework.boot:spring-boot-starter-web:${springBoot2Version}",
spring_cloud_build: "org.springframework.cloud:spring-cloud-build:${springCloudVersion}",
spring_cloud_starter_sleuth: "org.springframework.cloud:spring-cloud-starter-sleuth:${springCloudVersion}",
spring_context: "org.springframework:spring-context:${springVersion}",
spring_context_support: "org.springframework:spring-context-support:${springVersion}",
prometheus_simpleclient: "io.prometheus:simpleclient:${prometheusVersion}",
protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
opencensus_proto: "io.opencensus:opencensus-proto:${opencensusProtoVersion}",
gson: "com.google.code.gson:gson:${gsonVersion}",
httpcomponents: "org.apache.httpcomponents:httpclient:${httpcomponentsVersion}",
// Test dependencies.
guava_testlib: "com.google.guava:guava-testlib:${guavaVersion}",
junit: 'junit:junit:4.12',
mockito: 'org.mockito:mockito-core:2.28.1',
spring_test: "org.springframework:spring-test:${springVersion}",
truth: 'com.google.truth:truth:1.0',
spring_boot_test: "org.springframework.boot:spring-boot-starter-test:${springBootTestVersion}",
spring_boot_test2: "org.springframework.boot:spring-boot-starter-test:${springBoot2Version}",
dropwizard: "io.dropwizard.metrics:metrics-core:${dropwizardVersion}",
dropwizard5: "io.dropwizard.metrics5:metrics-core:${dropwizard5Version}",
sprint_boot_starter_tomcat: "org.springframework.boot:spring-boot-starter-tomcat:${springBoot2Version}",
javax_servlet: "javax.servlet:javax.servlet-api:${javaxServletVersion}",
]
}
configurations {
compile {
// Detect Maven Enforcer's dependencyConvergence failures. We only
// care for artifacts used as libraries by others.
if (!(project.name in ['benchmarks', 'opencensus-all'])) {
resolutionStrategy.failOnVersionConflict()
}
}
}
dependencies {
if (useCheckerFramework) {
ext.checkerFrameworkVersion = '2.10.1'
// 2.4.0 is the last version of the Checker Framework compiler that supports annotations
// in comments, though it should continue to work with newer versions of the Checker Framework.
// See
// https://github.com/census-instrumentation/opencensus-java/pull/1112#issuecomment-381366366.
ext.checkerFrameworkCompilerVersion = '2.4.0'
ext.jdkVersion = 'jdk8'
checkerFrameworkAnnotatedJDK "org.checkerframework:${jdkVersion}:${checkerFrameworkVersion}"
checkerFrameworkJavac "org.checkerframework:compiler:${checkerFrameworkCompilerVersion}"
compileOnly "org.checkerframework:checker:${checkerFrameworkVersion}"
compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
compileOnly libraries.auto_value
}
compileOnly libraries.errorprone,
libraries.jsr305
testCompile libraries.guava_testlib,
libraries.junit,
libraries.mockito,
libraries.truth
if (useErrorProne) {
// The ErrorProne plugin defaults to the latest, which would break our
// build if error prone releases a new version with a new check
errorprone "com.google.errorprone:error_prone_core:${errorProneVersion}"
}
}
findbugs {
toolVersion = findBugsAnnotationsVersion
ignoreFailures = false // bug free or it doesn't ship!
effort = 'max'
reportLevel = 'low' // low = sensitive to even minor mistakes
omitVisitors = [] // bugs that we want to ignore
excludeFilter = file("$rootDir/findbugs-exclude.xml")
}
// Generate html report for findbugs.
findbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
findbugsTest {
reports {
xml.enabled = false
html.enabled = true
}
}
findbugsJmh {
reports {
xml.enabled = false
html.enabled = true
}
}
checkstyle {
configFile = file("$rootDir/buildscripts/checkstyle.xml")
toolVersion = "8.12"
ignoreFailures = false
if (rootProject.hasProperty("checkstyle.ignoreFailures")) {
ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean()
}
configProperties["rootDir"] = rootDir
}
googleJavaFormat {
toolVersion '1.7'
}
afterEvaluate { // Allow subproject to add more source sets.
tasks.googleJavaFormat {
source = sourceSets*.allJava
include '**/*.java'
}
tasks.verifyGoogleJavaFormat {
source = sourceSets*.allJava
include '**/*.java'
}
}
signing {
required false
if (rootProject.hasProperty('signingUseGpgCmd')) {
useGpgCmd()
}
sign configurations.archives
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
jmh {
jmhVersion = '1.20'
warmupIterations = 10
iterations = 10
fork = 1
failOnError = true
resultFormat = 'JSON'
// Allow to run single benchmark class like:
// ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh
if (project.hasProperty('jmhIncludeSingleClass')) {
include = [
project.property('jmhIncludeSingleClass')
]
}
}
jmhReport {
jmhResultPath = project.file("${project.buildDir}/reports/jmh/results.json")
jmhReportOutput = project.file("${project.buildDir}/reports/jmh")
}
tasks.jmh.finalizedBy tasks.jmhReport
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
def configureAuth = {
if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
authentication(userName:rootProject.ossrhUsername, password: rootProject.ossrhPassword)
}
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/", configureAuth)
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/", configureAuth)
pom.project {
name "OpenCensus"
packaging 'jar'
description project.description
url 'https://github.com/census-instrumentation/opencensus-java'
scm {
connection 'scm:svn:https://github.com/census-instrumentation/opencensus-java'
developerConnection 'scm:git:git@github.com/census-instrumentation/opencensus-java'
url 'https://github.com/census-instrumentation/opencensus-java'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'io.opencensus'
name 'OpenCensus Contributors'
email 'census-developers@googlegroups.com'
url 'opencensus.io'
// https://issues.gradle.org/browse/GRADLE-2719
organization = 'OpenCensus Authors'
organizationUrl 'https://www.opencensus.io'
}
}
}
}
}
}
// Upload the following artifacts only:
uploadArchives.onlyIf {
name in ['opencensus-api',
'opencensus-contrib-agent',
'opencensus-contrib-appengine-standard-util',
'opencensus-contrib-dropwizard',
'opencensus-contrib-dropwizard5',
'opencensus-contrib-exemplar-util',
'opencensus-contrib-grpc-metrics',
'opencensus-contrib-grpc-util',
'opencensus-contrib-http-jaxrs',
'opencensus-contrib-http-jetty-client',
'opencensus-contrib-http-servlet',
'opencensus-contrib-http-util',
'opencensus-contrib-log-correlation-log4j2',
'opencensus-contrib-log-correlation-stackdriver',
'opencensus-contrib-observability-ready-util',
'opencensus-contrib-resource-util',
'opencensus-contrib-spring',
'opencensus-contrib-spring-sleuth-v1x',
'opencensus-contrib-spring-starter',
'opencensus-contrib-zpages',
'opencensus-exporter-metrics-ocagent',
'opencensus-exporter-metrics-util',
'opencensus-exporter-stats-prometheus',
'opencensus-exporter-stats-signalfx',
'opencensus-exporter-stats-stackdriver',
'opencensus-exporter-trace-datadog',
'opencensus-exporter-trace-elasticsearch',
'opencensus-exporter-trace-instana',
'opencensus-exporter-trace-logging',
'opencensus-exporter-trace-ocagent',
'opencensus-exporter-trace-stackdriver',
'opencensus-exporter-trace-zipkin',
'opencensus-exporter-trace-jaeger',
'opencensus-exporter-trace-util',
'opencensus-impl-core',
'opencensus-impl-lite',
'opencensus-impl',
'opencensus-testing']
}
// At a test failure, log the stack trace to the console so that we don't
// have to open the HTML in a browser.
test {
testLogging {
exceptionFormat = 'full'
showExceptions true
showCauses true
showStackTraces true
}
maxHeapSize = '1500m'
}
if (useCheckerFramework) {
allprojects {
tasks.withType(JavaCompile).all { JavaCompile compile ->
compile.doFirst {
compile.options.compilerArgs += [
'-Xmaxerrs', '10000',
"-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}",
"-AskipDefs=\\.AutoValue_|^io.opencensus.contrib.appengine.standard.util.TraceIdProto\$|^io.opencensus.contrib.appengine.standard.util.TraceProto\$",
"-AinvariantArrays"
]
options.fork = true
options.forkOptions.jvmArgs += ["-Xbootclasspath/p:${configurations.checkerFrameworkJavac.asPath}"]
}
}
}
}
// For projects that depend on gRPC during test execution, make sure to
// also configure ALPN if running on a platform (e.g. FreeBSD) that is not
// supported by io.netty:netty-tcnative-boringssl-static:jar. Also see:
// https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-with-jdk-jetty-alpnnpn
if (project.name in ['opencensus-exporter-stats-stackdriver',
'opencensus-exporter-trace-stackdriver']) {
def os = org.gradle.internal.os.OperatingSystem.current()
if (!os.isLinux() && !os.isWindows() && !os.isMacOsX()) {
configurations {
alpn
}
dependencies {
alpn 'org.mortbay.jetty.alpn:jetty-alpn-agent:2.0.7'
}
test {
jvmArgs "-javaagent:${configurations.alpn.asPath}"
}
}
}
}