Skip to content

Commit e5d436f

Browse files
committed
Sync more gradle with upstream
1 parent 715e391 commit e5d436f

3 files changed

Lines changed: 106 additions & 73 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id("ai.java-conventions")
3+
id("ai.shadow-conventions")
4+
5+
id("io.opentelemetry.instrumentation.muzzle-generation")
6+
id("io.opentelemetry.instrumentation.muzzle-check")
7+
}
8+
9+
val otelInstrumentationAlphaVersion: String by project
10+
11+
dependencies {
12+
compileOnly("io.opentelemetry:opentelemetry-sdk")
13+
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
14+
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
15+
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api")
16+
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator")
17+
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:$otelInstrumentationAlphaVersion")
18+
annotationProcessor("com.google.auto.service:auto-service")
19+
compileOnly("com.google.auto.service:auto-service")
20+
compileOnly(project(":agent:agent-bootstrap"))
21+
}
22+
23+
// Fix configuration cache compatibility for ByteBuddy tasks
24+
tasks.matching { it.name == "byteBuddyJava" }.configureEach {
25+
notCompatibleWithConfigurationCache("ByteBuddy tasks access Task.project at execution time")
26+
}
Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,3 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2-
31
plugins {
4-
id("ai.java-conventions")
5-
id("ai.shadow-conventions")
6-
7-
id("io.opentelemetry.instrumentation.muzzle-generation")
8-
id("io.opentelemetry.instrumentation.muzzle-check")
9-
}
10-
11-
val otelInstrumentationAlphaVersion: String by project
12-
13-
val testInstrumentation by configurations.creating
14-
15-
dependencies {
16-
compileOnly("io.opentelemetry:opentelemetry-sdk")
17-
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
18-
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
19-
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api")
20-
compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator")
21-
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:$otelInstrumentationAlphaVersion")
22-
annotationProcessor("com.google.auto.service:auto-service")
23-
compileOnly("com.google.auto.service:auto-service")
24-
compileOnly(project(":agent:agent-bootstrap"))
25-
26-
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:$otelInstrumentationAlphaVersion")
27-
// the bootstrap module is provided by the javaagent in the instrumentation test runtime, no need to include it
28-
// (especially when it's not being shaded)
29-
testCompileOnly(project(":agent:agent-bootstrap"))
30-
}
31-
32-
tasks.named<ShadowJar>("shadowJar").configure {
33-
configurations = listOf(project.configurations.runtimeClasspath.get(), testInstrumentation)
34-
35-
archiveFileName.set("agent-testing.jar")
36-
}
37-
38-
evaluationDependsOn(":agent:agent-for-testing")
39-
40-
tasks.withType<Test>().configureEach {
41-
val shadowJar = tasks.shadowJar.get()
42-
val agentShadowJar = project(":agent:agent-for-testing").tasks.shadowJar.get()
43-
44-
inputs.file(shadowJar.archiveFile)
45-
46-
dependsOn(shadowJar)
47-
dependsOn(agentShadowJar)
48-
49-
jvmArgs("-Dotel.javaagent.debug=true")
50-
jvmArgs("-javaagent:${agentShadowJar.archiveFile.get().asFile.absolutePath}")
51-
jvmArgs("-Dotel.javaagent.experimental.initializer.jar=${shadowJar.archiveFile.get().asFile.absolutePath}")
52-
jvmArgs("-Dotel.javaagent.testing.additional-library-ignores.enabled=false")
53-
jvmArgs("-Dotel.javaagent.testing.fail-on-context-leak=true")
54-
// prevent sporadic gradle deadlocks, see SafeLogger for more details
55-
jvmArgs("-Dotel.javaagent.testing.transform-safe-logging.enabled=true")
56-
// Reduce noise in assertion messages since we don't need to verify this in most tests. We check
57-
// in smoke tests instead.
58-
jvmArgs("-Dotel.javaagent.add-thread-details=false")
59-
// needed for proper GlobalMeterProvider registration
60-
jvmArgs("-Dotel.metrics.exporter=otlp")
61-
62-
// The sources are packaged into the testing jar so we need to make sure to exclude from the test
63-
// classpath, which automatically inherits them, to ensure our shaded versions are used.
64-
classpath = classpath.filter {
65-
if (file("${layout.buildDirectory.asFile.get()}/resources/main") == it || file("${layout.buildDirectory.asFile.get()}/classes/java/main") == it) {
66-
return@filter false
67-
}
68-
return@filter true
69-
}
70-
}
71-
72-
// Fix configuration cache compatibility for ByteBuddy tasks
73-
tasks.matching { it.name == "byteBuddyJava" }.configureEach {
74-
notCompatibleWithConfigurationCache("ByteBuddy tasks access Task.project at execution time")
2+
id("ai.javaagent-testing")
753
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.gradle.process.CommandLineArgumentProvider
3+
4+
plugins {
5+
id("ai.javaagent-instrumentation-base")
6+
}
7+
8+
val otelInstrumentationAlphaVersion: String by project
9+
10+
val testInstrumentation by configurations.creating {
11+
isCanBeConsumed = false
12+
isCanBeResolved = true
13+
}
14+
15+
val agentForTesting by configurations.creating {
16+
isCanBeConsumed = false
17+
isCanBeResolved = true
18+
}
19+
20+
class JavaagentTestArgumentsProvider(
21+
@InputFile
22+
@PathSensitive(PathSensitivity.RELATIVE)
23+
val agentShadowJar: File,
24+
25+
@InputFile
26+
@PathSensitive(PathSensitivity.RELATIVE)
27+
val shadowJar: File,
28+
) : CommandLineArgumentProvider {
29+
override fun asArguments(): Iterable<String> = listOf(
30+
"-Dotel.javaagent.debug=true",
31+
"-javaagent:${agentShadowJar.absolutePath}",
32+
// make the path to the javaagent available to tests
33+
"-Dotel.javaagent.testing.javaagent-jar-path=${agentShadowJar.absolutePath}",
34+
"-Dotel.javaagent.experimental.initializer.jar=${shadowJar.absolutePath}",
35+
"-Dotel.javaagent.testing.additional-library-ignores.enabled=false",
36+
"-Dotel.javaagent.testing.fail-on-context-leak=true",
37+
// prevent sporadic gradle deadlocks, see SafeLogger for more details
38+
"-Dotel.javaagent.testing.transform-safe-logging.enabled=true",
39+
// Reduce noise in assertion messages since we don't need to verify this in most tests. We check
40+
// in smoke tests instead.
41+
"-Dotel.javaagent.add-thread-details=false",
42+
// needed for proper GlobalMeterProvider registration
43+
"-Dotel.metrics.exporter=otlp"
44+
)
45+
}
46+
47+
dependencies {
48+
// Use your local agent-for-testing instead of the upstream one
49+
agentForTesting(project(":agent:agent-for-testing"))
50+
51+
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:$otelInstrumentationAlphaVersion")
52+
// the bootstrap module is provided by the javaagent in the instrumentation test runtime, no need to include it
53+
// (especially when it's not being shaded)
54+
testCompileOnly(project(":agent:agent-bootstrap"))
55+
}
56+
57+
tasks.named<ShadowJar>("shadowJar").configure {
58+
configurations = listOf(project.configurations.runtimeClasspath.get(), testInstrumentation)
59+
60+
archiveFileName.set("agent-testing.jar")
61+
}
62+
63+
// need to run this after evaluate because testSets plugin adds new test tasks
64+
afterEvaluate {
65+
tasks.withType<Test>().configureEach {
66+
val shadowJar = tasks.shadowJar.get()
67+
val agentShadowJar = project(":agent:agent-for-testing").tasks.shadowJar.get().archiveFile.get().asFile
68+
69+
dependsOn(shadowJar)
70+
dependsOn(project(":agent:agent-for-testing").tasks.shadowJar)
71+
72+
jvmArgumentProviders.add(
73+
JavaagentTestArgumentsProvider(
74+
agentShadowJar,
75+
shadowJar.archiveFile.get().asFile
76+
)
77+
)
78+
}
79+
}

0 commit comments

Comments
 (0)