283 lines
9.4 KiB
Groovy
283 lines
9.4 KiB
Groovy
import java.time.Duration
|
|
|
|
apply plugin: 'java-library'
|
|
apply plugin: 'groovy'
|
|
apply plugin: 'org.gradle.test-retry'
|
|
|
|
apply from: "$rootDir/gradle/spotless.gradle"
|
|
apply from: "$rootDir/gradle/codenarc.gradle"
|
|
apply from: "$rootDir/gradle/spotbugs.gradle"
|
|
apply from: "$rootDir/gradle/checkstyle.gradle"
|
|
|
|
afterEvaluate {
|
|
if (findProperty('mavenGroupId') == 'io.opentelemetry.javaagent.instrumentation') {
|
|
archivesBaseName = 'opentelemetry-javaagent-' + archivesBaseName
|
|
} else {
|
|
archivesBaseName = 'opentelemetry-' + archivesBaseName
|
|
}
|
|
}
|
|
|
|
// Version to use to compile code and run tests.
|
|
def DEFAULT_JAVA_VERSION = 11
|
|
|
|
def applyCodeCoverage = !(
|
|
project.path.startsWith(":smoke-tests") ||
|
|
//TODO why some tests fail on java 11 if jacoco is present?
|
|
project.path == ":javaagent" ||
|
|
project.path == ":load-generator" ||
|
|
project.path.startsWith(":benchmark") ||
|
|
project.path.startsWith(":instrumentation"))
|
|
|
|
if (applyCodeCoverage) {
|
|
apply from: "$rootDir/gradle/jacoco.gradle"
|
|
}
|
|
|
|
if (project.hasProperty("minJavaVersionForTests")) {
|
|
project.ext.release = project.getProperty("minJavaVersionForTests")
|
|
} else {
|
|
project.ext.release = JavaVersion.VERSION_1_8
|
|
}
|
|
|
|
java {
|
|
sourceCompatibility = JavaVersion.toVersion(project.ext.release)
|
|
targetCompatibility = JavaVersion.toVersion(project.ext.release)
|
|
|
|
toolchain {
|
|
languageVersion = JavaLanguageVersion.of(Math.max(project.ext.release.majorVersion.toInteger(), DEFAULT_JAVA_VERSION))
|
|
}
|
|
|
|
// See https://docs.gradle.org/current/userguide/upgrading_version_5.html, Automatic target JVM version
|
|
disableAutoTargetJvm()
|
|
withJavadocJar()
|
|
withSourcesJar()
|
|
}
|
|
|
|
tasks.withType(JavaCompile) {
|
|
options.release = project.ext.release.majorVersion.toInteger()
|
|
}
|
|
tasks.withType(GroovyCompile) {
|
|
options.release = project.ext.release.majorVersion.toInteger()
|
|
}
|
|
tasks.withType(ScalaCompile) {
|
|
options.release = project.ext.release.majorVersion.toInteger()
|
|
}
|
|
|
|
apply plugin: "eclipse"
|
|
eclipse {
|
|
classpath {
|
|
downloadSources = true
|
|
downloadJavadoc = true
|
|
}
|
|
}
|
|
if (configurations.find { it.name == 'jmh' }) {
|
|
eclipse.classpath.plusConfigurations += [configurations.jmh]
|
|
}
|
|
|
|
jar {
|
|
/*
|
|
Make Jar build fail on duplicate files
|
|
|
|
By default Gradle Jar task can put multiple files with the same name
|
|
into a Jar. This may lead to confusion. For example if auto-service
|
|
annotation processing creates files with same name in `scala` and
|
|
`java` directory this would result in Jar having two files with the
|
|
same name in it. Which in turn would result in only one of those
|
|
files being actually considered when that Jar is used leading to very
|
|
confusing failures.
|
|
|
|
Instead we should 'fail early' and avoid building such Jars.
|
|
*/
|
|
duplicatesStrategy = 'fail'
|
|
}
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
jcenter()
|
|
maven {
|
|
url "https://repo.typesafe.com/typesafe/releases"
|
|
}
|
|
// this is only needed for the working against unreleased otel-java snapshots
|
|
maven {
|
|
url "https://oss.jfrog.org/artifactory/oss-snapshot-local"
|
|
content {
|
|
includeGroup "io.opentelemetry"
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
compileOnly group: 'org.checkerframework', name: 'checker-qual', version: versions.checkerFramework
|
|
|
|
testImplementation enforcedPlatform(group: 'org.junit', name: 'junit-bom', version: versions.junit5)
|
|
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api'
|
|
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params'
|
|
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'
|
|
testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine'
|
|
|
|
testImplementation deps.spock
|
|
testImplementation deps.groovy
|
|
testImplementation deps.testLogging
|
|
testImplementation group: 'info.solidsoft.spock', name: 'spock-global-unroll', version: '0.5.1'
|
|
testImplementation group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.19.0'
|
|
|
|
constraints {
|
|
// need to pin the opentelemetry-sdk transitive dependency versions explicitly, otherwise the
|
|
// latest snapshots are used, because the opentelemetry-sdk snapshot pom references these
|
|
// transitive dependencies using the generic SNAPSHOT instead of a specific snapshot
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-api', version: versions.opentelemetry
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-context', version: versions.opentelemetryContext
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk', version: versions.opentelemetryAnother
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk-baggage', version: versions.opentelemetry
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk-common', version: versions.opentelemetry
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-proto', version: versions.opentelemetryAnother
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk-extension-otproto', version: versions.opentelemetryAnother
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk-metrics', version: versions.opentelemetry
|
|
implementation group: 'io.opentelemetry', name: 'opentelemetry-sdk-tracing', version: versions.opentelemetryAnother
|
|
}
|
|
}
|
|
|
|
jar {
|
|
manifest {
|
|
attributes(
|
|
"Implementation-Title": project.name,
|
|
"Implementation-Version": project.version,
|
|
"Implementation-Vendor": "OpenTelemetry",
|
|
"Implementation-URL": "https://github.com/open-telemetry/opentelemetry-java-instrumentation",
|
|
)
|
|
}
|
|
}
|
|
|
|
javadoc {
|
|
options.addStringOption('Xdoclint:none', '-quiet')
|
|
|
|
doFirst {
|
|
if (project.ext.has("apiLinks")) {
|
|
options.links(*project.apiLinks)
|
|
}
|
|
}
|
|
source = sourceSets.main.allJava
|
|
classpath = configurations.compileClasspath
|
|
|
|
options {
|
|
encoding = "utf-8"
|
|
docEncoding = "utf-8"
|
|
charSet = "utf-8"
|
|
|
|
setMemberLevel JavadocMemberLevel.PUBLIC
|
|
setAuthor true
|
|
|
|
links "https://docs.oracle.com/javase/8/docs/api/"
|
|
source = 8
|
|
}
|
|
}
|
|
|
|
project.afterEvaluate {
|
|
if (project.plugins.hasPlugin('org.unbroken-dome.test-sets') && configurations.hasProperty("latestDepTestRuntime")) {
|
|
tasks.withType(Test).configureEach {
|
|
doFirst {
|
|
def testArtifacts = configurations.testRuntimeClasspath.resolvedConfiguration.resolvedArtifacts
|
|
def latestTestArtifacts = configurations.latestDepTestRuntimeClasspath.resolvedConfiguration.resolvedArtifacts
|
|
assert testArtifacts != latestTestArtifacts: "latestDepTest dependencies are identical to test"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def isJavaVersionAllowed(JavaVersion version) {
|
|
if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests').compareTo(version) > 0) {
|
|
return false
|
|
}
|
|
if (project.hasProperty('maxJavaVersionForTests') && project.getProperty('maxJavaVersionForTests').compareTo(version) < 0) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// We default to testing with Java 11 for most tests, but some tests don't support it, where we change
|
|
// the default test task's version so commands like `./gradlew check` can test all projects regardless
|
|
// of Java version.
|
|
if (!isJavaVersionAllowed(JavaVersion.toVersion(DEFAULT_JAVA_VERSION))) {
|
|
tasks.withType(Test) {
|
|
javaLauncher = javaToolchains.launcherFor {
|
|
languageVersion = JavaLanguageVersion.of(project.getProperty('maxJavaVersionForTests').majorVersion)
|
|
}
|
|
}
|
|
}
|
|
|
|
def addTestRule(String testTaskName) {
|
|
def prefix = testTaskName + "Java"
|
|
tasks.addRule("Pattern: $prefix<Version>: Runs tests using given java version") { String taskName ->
|
|
if (taskName.startsWith(prefix)) {
|
|
def requestedJavaVersion = JavaVersion.toVersion(taskName - prefix)
|
|
def gradleJavaVersion = JavaVersion.current()
|
|
|
|
if (gradleJavaVersion != requestedJavaVersion) {
|
|
tasks.withType(Test).all {
|
|
javaLauncher = javaToolchains.launcherFor {
|
|
languageVersion = JavaLanguageVersion.of(requestedJavaVersion.majorVersion)
|
|
}
|
|
enabled = isJavaVersionAllowed(requestedJavaVersion)
|
|
}
|
|
}
|
|
|
|
task(taskName) {
|
|
if (project.tasks.findByName(testTaskName) != null) {
|
|
dependsOn testTaskName
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
addTestRule("test")
|
|
|
|
tasks.withType(Test).configureEach {
|
|
useJUnitPlatform()
|
|
|
|
// All tests must complete within 15 minutes.
|
|
// This value is quite big because with lower values (3 mins) we were experiencing large number of false positives
|
|
timeout = Duration.ofMinutes(15)
|
|
|
|
// Disable all tests if skipTests property was specified
|
|
enabled = !project.rootProject.hasProperty("skipTests")
|
|
|
|
retry {
|
|
// You can see tests that were retried by this mechanism in the collected test reports and build scans.
|
|
maxRetries = System.getenv("CI") != null ? 5 : 0
|
|
}
|
|
|
|
reports {
|
|
junitXml.outputPerTestCase = true
|
|
}
|
|
|
|
testLogging {
|
|
exceptionFormat = 'full'
|
|
}
|
|
}
|
|
|
|
tasks.withType(AbstractArchiveTask) {
|
|
preserveFileTimestamps = false
|
|
reproducibleFileOrder = true
|
|
}
|
|
|
|
plugins.withId('net.ltgt.errorprone') {
|
|
dependencies {
|
|
annotationProcessor group: "com.uber.nullaway", name: "nullaway", version: versions.nullaway
|
|
errorprone group: "com.google.errorprone", name: "error_prone_core", version: versions.errorprone
|
|
}
|
|
|
|
tasks.withType(JavaCompile) {
|
|
if (!name.toLowerCase().contains("test")) {
|
|
options.errorprone {
|
|
error("NullAway")
|
|
|
|
// Doesn't work well with Java 8
|
|
disable("FutureReturnValueIgnored")
|
|
|
|
option("NullAway:AnnotatedPackages", "io.opentelemetry,com.linecorp.armeria,com.google.common")
|
|
}
|
|
}
|
|
}
|
|
}
|