opentelemetry-java-instrume.../javaagent/javaagent.gradle

154 lines
4.1 KiB
Groovy

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jk1.license.filter.LicenseBundleNormalizer
import com.github.jk1.license.render.InventoryMarkdownReportRenderer
plugins {
id "otel.shadow-conventions"
id "com.github.jk1.dependency-license-report" version "1.16"
}
description = 'OpenTelemetry Javaagent'
group = 'io.opentelemetry.javaagent'
apply plugin: "otel.java-conventions"
apply from: "$rootDir/gradle/publish.gradle"
configurations {
shadowInclude {
canBeResolved = true
canBeConsumed = false
}
}
processResources {
from(rootProject.file("licenses")) {
into("META-INF/licenses")
}
}
jar {
manifest {
attributes(
"Main-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Agent-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Premain-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Can-Redefine-Classes": true,
"Can-Retransform-Classes": true,
)
}
}
CopySpec isolateSpec(Collection<Project> projectsWithShadowJar) {
return copySpec {
from({ projectsWithShadowJar.tasks.shadowJar.collect { zipTree(it.archiveFile) } }) {
// important to keep prefix 'inst' short, as it is prefixed to lots of strings in runtime mem
into 'inst'
rename '(^.*)\\.class$', '$1.classdata'
// Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
rename '^LICENSE$', 'LICENSE.renamed'
}
}
}
//Includes everything needed for OOTB experience
shadowJar {
def projectsWithShadowJar = [project(':instrumentation'), project(":javaagent-exporters")]
projectsWithShadowJar.each {
dependsOn("${it.path}:shadowJar")
}
with isolateSpec(projectsWithShadowJar)
}
//Includes instrumentations, but not exporters
task lightShadow(type: ShadowJar) {
dependsOn ':instrumentation:shadowJar'
def projectsWithShadowJar = [project(':instrumentation')]
with isolateSpec(projectsWithShadowJar)
}
publishing {
publications {
maven(MavenPublication) {
artifact lightShadow
}
}
}
tasks.withType(ShadowJar).configureEach {
configurations = [project.configurations.shadowInclude]
manifest {
inheritFrom project.tasks.jar.manifest
}
}
configurations {
licenseReportDependencies
}
dependencies {
testCompileOnly project(':javaagent-bootstrap')
testCompileOnly project(':javaagent-api')
testImplementation "com.google.guava:guava"
testImplementation 'io.opentracing.contrib.dropwizard:dropwizard-opentracing:0.2.2'
shadowInclude project(path: ':javaagent-bootstrap')
// We only have compileOnly dependencies on these to make sure they don't leak into POMs.
licenseReportDependencies("com.github.ben-manes.caffeine:caffeine") {
transitive = false
}
licenseReportDependencies "com.blogspot.mydailyjava:weak-lock-free"
// TODO ideally this would be :instrumentation instead of :javaagent-tooling
// in case there are dependencies (accidentally) pulled in by instrumentation modules
// but I couldn't get that to work
licenseReportDependencies project(':javaagent-tooling')
licenseReportDependencies project(':javaagent-extension-api')
licenseReportDependencies project(':javaagent-bootstrap')
}
tasks.withType(Test).configureEach {
inputs.file(shadowJar.archiveFile)
jvmArgs "-Dotel.javaagent.debug=true"
doFirst {
// Defining here to allow jacoco to be first on the command line.
jvmArgs "-javaagent:${shadowJar.archivePath}"
}
testLogging {
events "started"
}
dependsOn shadowJar
}
assemble.dependsOn lightShadow
assemble.dependsOn shadowJar
licenseReport {
outputDir = rootProject.file("licenses")
renderers = [new InventoryMarkdownReportRenderer()]
configurations = ["licenseReportDependencies"]
excludeGroups = [
"io.opentelemetry.instrumentation",
"io.opentelemetry.javaagent"
]
filters = [new LicenseBundleNormalizer(bundlePath: "$projectDir/license-normalizer-bundle.json")]
}
def cleanLicenses = tasks.register("cleanLicenses", Delete) {
delete(rootProject.file("licenses"))
}
tasks.named("generateLicenseReport").configure {
dependsOn(cleanLicenses)
}