import nebula.plugin.release.git.opinion.Strategies plugins { id "com.diffplug.spotless" id "com.github.ben-manes.versions" id "com.jfrog.artifactory" apply false id "com.jfrog.bintray" apply false id "nebula.release" id "net.ltgt.errorprone" apply false id "ru.vyarus.animalsniffer" apply false id "io.morethan.jmhreport" apply false } if (!JavaVersion.current().isJava11Compatible()) { throw new GradleException("JDK 11 or higher is required to build. " + "One option is to download it from https://adoptopenjdk.net/. If you believe you already " + "have it, please check that the JAVA_HOME environment variable is pointing at the " + "JDK 11 installation.") } ext { opentelemetryProjects = subprojects - project(":opentelemetry-bom") } // Nebula plugin will not configure if .git doesn't exist, let's allow building on it by stubbing it // out. This supports building from the zip archive downloaded from GitHub. def releaseTask if (file('.git').exists()) { release { defaultVersionStrategy = Strategies.getSNAPSHOT() } nebulaRelease { addReleaseBranchPattern(/v\d+\.\d+\.x/) } releaseTask = tasks.named("release") releaseTask.configure { mustRunAfter("snapshotSetup", "finalSetup") } } else { releaseTask = tasks.register('release') } subprojects { group = "io.opentelemetry" plugins.withId("maven-publish") { // Always include the artifactory/bintray plugins to do the deployment. pluginManager.apply "com.jfrog.artifactory" pluginManager.apply "com.jfrog.bintray" releaseTask.configure { if (version.toString().endsWith('-SNAPSHOT')) { finalizedBy(tasks.named('artifactoryPublish')) } else { finalizedBy(tasks.named('bintrayUpload')) } } publishing { publications { mavenPublication(MavenPublication) { version version groupId group plugins.withId("java-platform") { from(components["javaPlatform"]) } plugins.withId("java-library") { from(components["java"]) } versionMapping { allVariants { fromResolutionResult() } } pom { name = 'OpenTelemetry Java' url = 'https://github.com/open-telemetry/opentelemetry-java' licenses { license { name = 'The Apache License, Version 2.0' url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id = 'opentelemetry' name = 'OpenTelemetry Gitter' url = 'https://gitter.im/open-telemetry/community' } } scm { connection = 'scm:git:git@github.com:open-telemetry/opentelemetry-java.git' developerConnection = 'scm:git:git@github.com:open-telemetry/opentelemetry-java.git' url = 'git@github.com:open-telemetry/opentelemetry-java.git' } afterEvaluate { // description is not available until evaluated. description = project.description } } } } } // Snapshot publishing. artifactory { contextUrl = 'https://oss.jfrog.org' publish { repository { repoKey = 'oss-snapshot-local' username = System.getenv("BINTRAY_USER") password = System.getenv("BINTRAY_KEY") } defaults { publications('mavenPublication') publishArtifacts = true publishPom = true } } resolve { repoKey = 'libs-release' } } artifactoryPublish { enabled = version.toString().endsWith('-SNAPSHOT') } // Release artifacts publishing. bintray { user = System.getenv("BINTRAY_USER") key = System.getenv("BINTRAY_KEY") publications = ['mavenPublication'] publish = true pkg { repo = 'maven' name = 'opentelemetry-java' licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/open-telemetry/opentelemetry-java.git' userOrg = 'open-telemetry' githubRepo = 'open-telemetry/opentelemetry-java' version { name = project.version gpg { sign = true } mavenCentralSync { user = System.getenv("SONATYPE_USER") password = System.getenv("SONATYPE_KEY") } } } } } } configure(opentelemetryProjects) { apply plugin: 'checkstyle' apply plugin: 'eclipse' apply plugin: 'java' apply plugin: 'java-library' apply plugin: 'idea' apply plugin: 'signing' apply plugin: 'jacoco' apply plugin: 'com.diffplug.spotless' apply plugin: 'net.ltgt.errorprone' repositories { mavenCentral() jcenter() mavenLocal() } java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 toolchain { languageVersion = JavaLanguageVersion.of(11) } withJavadocJar() withSourcesJar() } tasks { def testJava8 = register('testJava8', Test) { javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(8) } jacoco.enabled = false } if (rootProject.findProperty('testAdditionalJavaVersions') == 'true') { check.dependsOn(testJava8) } } tasks.withType(JavaCompile) { it.options.release = 8 it.options.compilerArgs += [ "-Xlint:all", // 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. "-Xlint:-try", // We suppress the "processing" warning as suggested in // https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM "-Xlint:-processing", // We suppress the "options" warning because it prevents compilation on modern JDKs "-Xlint:-options", ] it.options.errorprone.disableWarningsInGeneratedCode = true it.options.errorprone.allDisabledChecksAsWarnings = true // Doesn't currently use Var annotations. it.options.errorprone.disable("Var") // "-Xep:Var:OFF" // ImmutableRefactoring suggests using com.google.errorprone.annotations.Immutable, // but currently uses javax.annotation.concurrent.Immutable it.options.errorprone.disable("ImmutableRefactoring") // "-Xep:ImmutableRefactoring:OFF" // AutoValueImmutableFields suggests returning Guava types from API methods it.options.errorprone.disable("AutoValueImmutableFields") // "-Xep:AutoValueImmutableFields:OFF" it.options.encoding = "UTF-8" // Ignore warnings for protobuf and jmh generated files. it.options.errorprone.excludedPaths = ".*generated.*" // "-XepExcludedPaths:.*/build/generated/source/proto/.*" it.options.errorprone.disable("Java7ApiChecker") it.options.errorprone.disable("AndroidJdkLibsChecker") //apparently disabling android doesn't disable this it.options.errorprone.disable("StaticOrDefaultInterfaceMethod") //until we have everything converted, we need these it.options.errorprone.disable("JdkObsolete") it.options.errorprone.disable("UnnecessaryAnonymousClass") it.options.compilerArgs += ["-Werror"] } compileTestJava { // serialVersionUID is basically guaranteed to be useless in tests options.compilerArgs += ["-Xlint:-serial"] // Disable Java7 checks in test sources // options.errorprone.disable("Java7ApiChecker") // Disable AndroidJdkLibs checks in test sources // options.errorprone.disable("AndroidJdkLibsChecker") } 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) } ext { autoValueVersion = '1.7.4' errorProneVersion = '2.4.0' errorProneJavacVersion = '9+181-r4173-1' findBugsJsr305Version = '3.0.2' grpcVersion = '1.33.1' guavaVersion = '30.0-android' jacksonVersion = '2.11.3' jmhVersion = '1.26' junitVersion = '5.7.0' mockitoVersion = '3.6.0' opencensusVersion = '0.28.2' opentracingVersion = '0.33.0' prometheusVersion = '0.9.0' protobufVersion = '3.14.0' protocVersion = '3.14.0' zipkinReporterVersion = '2.12.2' zipkinVersion = '2.18.3' boms = [ grpc : "io.grpc:grpc-bom:${grpcVersion}", guava : "com.google.guava:guava-bom:${guavaVersion}", jackson : "com.fasterxml.jackson:jackson-bom:2.11.3", junit : "org.junit:junit-bom:${junitVersion}", protobuf : "com.google.protobuf:protobuf-bom:${protobufVersion}", zipkin_reporter: "io.zipkin.reporter2:zipkin-reporter-bom:${zipkinReporterVersion}" ] libraries = [ auto_value : "com.google.auto.value:auto-value:${autoValueVersion}", auto_value_annotation : "com.google.auto.value:auto-value-annotations:${autoValueVersion}", disruptor : "com.lmax:disruptor:3.4.2", errorprone_annotation : "com.google.errorprone:error_prone_annotations:${errorProneVersion}", errorprone_core : "com.google.errorprone:error_prone_core:${errorProneVersion}", errorprone_javac : "com.google.errorprone:javac:${errorProneJavacVersion}", grpc_api : "io.grpc:grpc-api", grpc_context : "io.grpc:grpc-context", grpc_protobuf : "io.grpc:grpc-protobuf", grpc_stub : "io.grpc:grpc-stub", guava : "com.google.guava:guava", javax_annotations : "javax.annotation:javax.annotation-api:1.3.2", jmh_core : "org.openjdk.jmh:jmh-core:${jmhVersion}", jmh_bytecode : "org.openjdk.jmh:jmh-generator-bytecode:${jmhVersion}", jsr305 : "com.google.code.findbugs:jsr305:${findBugsJsr305Version}", prometheus_client : "io.prometheus:simpleclient:${prometheusVersion}", prometheus_client_common: "io.prometheus:simpleclient_common:${prometheusVersion}", protobuf : "com.google.protobuf:protobuf-java", protobuf_util : "com.google.protobuf:protobuf-java-util", zipkin_reporter : "io.zipkin.reporter2:zipkin-reporter", zipkin_okhttp : "io.zipkin.reporter2:zipkin-sender-okhttp3", // Compatibility layer opencensus_api : "io.opencensus:opencensus-api:${opencensusVersion}", opencensus_impl : "io.opencensus:opencensus-impl:${opencensusVersion}", opencensus_impl_core : "io.opencensus:opencensus-impl-core:${opencensusVersion}", opentracing : "io.opentracing:opentracing-api:${opentracingVersion}", // Test dependencies. assertj : "org.assertj:assertj-core:3.18.1", guava_testlib : "com.google.guava:guava-testlib", junit : 'junit:junit:4.13.1', junit_pioneer : 'org.junit-pioneer:junit-pioneer:1.0.0', junit_jupiter_api : 'org.junit.jupiter:junit-jupiter-api', junit_jupiter_engine : 'org.junit.jupiter:junit-jupiter-engine', junit_vintage_engine : 'org.junit.vintage:junit-vintage-engine', mockito : "org.mockito:mockito-core:${mockitoVersion}", mockito_junit_jupiter : "org.mockito:mockito-junit-jupiter:${mockitoVersion}", okhttp : 'com.squareup.okhttp3:okhttp:3.14.9', system_rules : 'com.github.stefanbirkner:system-rules:1.19.0', // env and system properties slf4jsimple : 'org.slf4j:slf4j-simple:1.7.30', // Compatibility layer awaitility : 'org.awaitility:awaitility:4.0.3', testcontainers : 'org.testcontainers:junit-jupiter:1.15.0', rest_assured : 'io.rest-assured:rest-assured:4.2.0', jaeger_client : 'io.jaegertracing:jaeger-client:1.5.0', // Jaeger Client zipkin_junit : "io.zipkin.zipkin2:zipkin-junit:${zipkinVersion}", // Zipkin JUnit rule archunit : 'com.tngtech.archunit:archunit-junit4:0.14.1', //Architectural constraints jqf : 'edu.berkeley.cs.jqf:jqf-fuzz:1.6', // fuzz testing // Tooling android_signature : 'com.toasttab.android:gummy-bears-api-24:0.3.0:coreLib@signature' ] } checkstyle { configFile = file("$rootDir/buildscripts/checkstyle.xml") toolVersion = "8.12" ignoreFailures = false configProperties["rootDir"] = rootDir } jacoco { toolVersion = "0.8.6" } spotless { java { googleJavaFormat("1.9") licenseHeaderFile rootProject.file('buildscripts/spotless.license.java'), '(package|import|class|// Includes work from:)' } } configurations { compile { // Detect Maven Enforcer's dependencyConvergence failures. We only // care for artifacts used as libraries by others. // TODO: Enable failOnVersionConflict() resolutionStrategy.preferProjectModules() } } dependencies { configurations.all { // Kotlin compiler classpaths don't support BOM nor need it. if (it.name.endsWith('Classpath') && !it.name.startsWith('kotlin')) { add(it.name, enforcedPlatform(boms.grpc)) add(it.name, enforcedPlatform(boms.guava)) add(it.name, enforcedPlatform(boms.jackson)) add(it.name, enforcedPlatform(boms.junit)) add(it.name, enforcedPlatform(boms.protobuf)) add(it.name, enforcedPlatform(boms.zipkin_reporter)) } } compileOnly libraries.auto_value_annotation, libraries.errorprone_annotation, libraries.jsr305 testCompileOnly libraries.auto_value_annotation, libraries.errorprone_annotation, libraries.jsr305 testImplementation libraries.junit_jupiter_api, libraries.mockito, libraries.mockito_junit_jupiter, libraries.assertj, libraries.awaitility testRuntimeOnly libraries.junit_jupiter_engine, libraries.junit_vintage_engine // The ErrorProne plugin defaults to the latest, which would break our // build if error prone releases a new version with a new check errorprone libraries.errorprone_core annotationProcessor "com.google.guava:guava-beta-checker:1.0" // Workaround for @javax.annotation.Generated // see: https://github.com/grpc/grpc-java/issues/3633 compileOnly libraries.javax_annotations } tasks.withType(Test) { useJUnitPlatform() // At a test failure, log the stack trace to the console so that we don't // have to open the HTML in a browser. testLogging { exceptionFormat = 'full' showExceptions = true showCauses = true showStackTraces = true } maxHeapSize = '1500m' } javadoc.options { source = "8" encoding = "UTF-8" links 'https://docs.oracle.com/javase/8/docs/api/' addBooleanOption('Xdoclint:all,-missing', true) } afterEvaluate { jar { inputs.property("moduleName", moduleName) manifest { attributes('Automatic-Module-Name': moduleName) } } } signing { required false sign configurations.archives } plugins.withId("ru.vyarus.animalsniffer") { animalsnifferTest { enabled = false } // If JMH enabled ignore animalsniffer. plugins.withId("me.champeau.gradle.jmh") { animalsnifferJmh { enabled = false } } } plugins.withId("me.champeau.gradle.jmh") { // Always include the jmhreport plugin and run it after jmh task. pluginManager.apply "io.morethan.jmhreport" dependencies { jmh libraries.jmh_core, libraries.jmh_bytecode } // invoke jmh on a single benchmark class like so: // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh jmh { failOnError = true resultFormat = 'JSON' // Otherwise an error will happen: // Could not expand ZIP 'byte-buddy-agent-1.9.7.jar'. includeTests = false profilers = ["gc"] 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") } // Always run jmhReport after jmh task. tasks.jmh.finalizedBy tasks.jmhReport } } wrapper { gradleVersion = '6.7' } allprojects { tasks.register("updateVersionInDocs") { group("documentation") doLast { def versionParts = version.toString().split('\\.') def minorVersionNumber = Integer.parseInt(versionParts[1]) def nextSnapshot = "${versionParts[0]}.${minorVersionNumber + 1}.0-SNAPSHOT" def readme = file("README.md") if (!readme.exists()) return def readmeText = readme.text def updatedText = readmeText .replaceAll("\\d+\\.\\d+\\.\\d+", "${version}") .replaceAll("\\d+\\.\\d+\\.\\d+-SNAPSHOT", "${nextSnapshot}") .replaceAll("(implementation.*io\\.opentelemetry:.*:)(\\d+\\.\\d+\\.\\d+)(?!-SNAPSHOT)(.*)", "\$1${version}\$3") .replaceAll("(implementation.*io\\.opentelemetry:.*:)(\\d+\\.\\d+\\.\\d+-SNAPSHOT)(.*)", "\$1${nextSnapshot}\$3") .replaceAll(".*", "${version}") readme.text = updatedText } } }