Skip to content

Commit f982bad

Browse files
runningcodeclaude
andauthored
build(samples): Remove outputs.upToDateWhen { false } from systemTest tasks (#5522)
* build(samples): Remove outputs.upToDateWhen { false } from systemTest tasks The systemTest tasks in the sample modules forced Gradle to always treat their outputs as out of date, disabling up-to-date checks and build cache reuse. Removing this lets Gradle rely on its normal input/output tracking for the Test tasks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * build(samples): Track systemTest app archive via convention plugin The system tests launch the packaged sample (war/shadowJar/bootJar) from build/libs as a separate process, so the archive is a real input to the systemTest task even though it is not on the test classpath. Without it, removing outputs.upToDateWhen { false } would let Gradle mark systemTest up-to-date while a separate jar build refreshed the artifact, skipping verification against the rebuilt sample. Move that wiring into a single io.sentry.systemtest convention plugin in build-logic instead of repeating it in every sample build file. The plugin auto-detects the packaging task (war, else shadowJar, else bootJar), mirroring the selection in test/system-test-runner.py, and declares its archive as an input and dependency. Each sample just applies the plugin. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * build(samples): Track OpenTelemetry agent jar as systemTest input The agent-based OpenTelemetry samples are launched by the runner with -javaagent:<sentry-opentelemetry-agent>, started outside the test JVM. That jar is not on the test classpath nor one of the app archives, so without tracking it systemTest could stay up-to-date and be skipped while the runner launches a newer agent. Add a usesOpenTelemetryAgent opt-in to the io.sentry.systemtest plugin; the three agent samples enable it and the agent jar is then tracked as a content input. The runner already builds and launches the agent before invoking the task, so it is tracked by path without a cross-project task dependency, which keeps it configuration-on-demand and configuration cache compatible. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 57d359a commit f982bad

24 files changed

Lines changed: 86 additions & 44 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import io.sentry.gradle.SystemTestExtension
2+
import org.gradle.api.tasks.ClasspathNormalizer
3+
4+
val systemTest = extensions.create<SystemTestExtension>("sentrySystemTest")
5+
6+
// The sample system tests launch the packaged app (war/shadowJar/bootJar) from build/libs as a
7+
// separate process, so the archive is a real input even though it is not on the test classpath.
8+
// Agent-based samples are additionally launched with -javaagent:<otel agent>, another runtime
9+
// input not on the classpath. See test/system-test-runner.py.
10+
tasks.matching { it.name == "systemTest" }.configureEach {
11+
val archiveTask =
12+
listOf("war", "shadowJar", "bootJar").firstOrNull { it in tasks.names }
13+
?: throw GradleException(
14+
"io.sentry.systemtest is applied to $path but none of war/shadowJar/bootJar " +
15+
"exist to provide the launched app archive for the systemTest task"
16+
)
17+
// Declaring the archive as an input also wires the dependency on its producing task.
18+
inputs
19+
.files(tasks.named(archiveTask))
20+
.withPropertyName("appArchive")
21+
.withNormalizer(ClasspathNormalizer::class.java)
22+
23+
if (systemTest.usesOpenTelemetryAgent.get()) {
24+
// The runner builds the agent and launches the app with -javaagent before invoking this task,
25+
// so the agent jar is tracked for content only (by path, no cross-project task dependency): a
26+
// change to it makes systemTest out of date even though it runs outside the test JVM.
27+
val version = providers.gradleProperty("versionName").get()
28+
inputs
29+
.files(
30+
rootProject.layout.projectDirectory.file(
31+
"sentry-opentelemetry/sentry-opentelemetry-agent/build/libs/" +
32+
"sentry-opentelemetry-agent-$version.jar"
33+
)
34+
)
35+
.withPropertyName("openTelemetryAgent")
36+
.withNormalizer(ClasspathNormalizer::class.java)
37+
}
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.sentry.gradle
2+
3+
import org.gradle.api.provider.Property
4+
5+
/** Configuration for the `io.sentry.systemtest` convention plugin. */
6+
abstract class SystemTestExtension {
7+
/**
8+
* Set to `true` for samples that the system-test runner launches with the Sentry OpenTelemetry
9+
* Java agent (`-javaagent`). The agent jar is then tracked as a `systemTest` input so the task
10+
* re-runs when the agent changes, even though it is started outside the test JVM.
11+
*/
12+
abstract val usesOpenTelemetryAgent: Property<Boolean>
13+
14+
init {
15+
usesOpenTelemetryAgent.convention(false)
16+
}
17+
}

sentry-samples/sentry-samples-console-opentelemetry-noagent/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.console.Main") }
@@ -71,8 +72,6 @@ tasks.register<Test>("systemTest").configure {
7172
testClassesDirs = test.output.classesDirs
7273
classpath = test.runtimeClasspath
7374

74-
outputs.upToDateWhen { false }
75-
7675
maxParallelForks = 1
7776

7877
// Cap JVM args per test

sentry-samples/sentry-samples-console-otlp/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.console.Main") }
@@ -74,8 +75,6 @@ tasks.register<Test>("systemTest").configure {
7475
testClassesDirs = test.output.classesDirs
7576
classpath = test.runtimeClasspath
7677

77-
outputs.upToDateWhen { false }
78-
7978
maxParallelForks = 1
8079

8180
// Cap JVM args per test

sentry-samples/sentry-samples-console/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.console.Main") }
@@ -75,8 +76,6 @@ tasks.register<Test>("systemTest").configure {
7576
testClassesDirs = test.output.classesDirs
7677
classpath = test.runtimeClasspath
7778

78-
outputs.upToDateWhen { false }
79-
8079
maxParallelForks = 1
8180

8281
// Cap JVM args per test

sentry-samples/sentry-samples-jul/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.jul.Main") }
@@ -66,8 +67,6 @@ tasks.register<Test>("systemTest").configure {
6667
testClassesDirs = test.output.classesDirs
6768
classpath = test.runtimeClasspath
6869

69-
outputs.upToDateWhen { false }
70-
7170
maxParallelForks = 1
7271

7372
// Cap JVM args per test

sentry-samples/sentry-samples-log4j2/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.log4j2.Main") }
@@ -72,8 +73,6 @@ tasks.register<Test>("systemTest").configure {
7273
testClassesDirs = test.output.classesDirs
7374
classpath = test.runtimeClasspath
7475

75-
outputs.upToDateWhen { false }
76-
7776
maxParallelForks = 1
7877

7978
// Cap JVM args per test

sentry-samples/sentry-samples-logback/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.kotlin.jvm)
77
alias(libs.plugins.gradle.versions)
88
alias(libs.plugins.shadow)
9+
id("io.sentry.systemtest")
910
}
1011

1112
application { mainClass.set("io.sentry.samples.logback.Main") }
@@ -66,8 +67,6 @@ tasks.register<Test>("systemTest").configure {
6667
testClassesDirs = test.output.classesDirs
6768
classpath = test.runtimeClasspath
6869

69-
outputs.upToDateWhen { false }
70-
7170
maxParallelForks = 1
7271

7372
// Cap JVM args per test

sentry-samples/sentry-samples-spring-7/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ plugins {
1010
alias(libs.plugins.kotlin.spring)
1111
id("war")
1212
alias(libs.plugins.gretty)
13+
id("io.sentry.systemtest")
1314
}
1415

1516
application { mainClass.set("io.sentry.samples.spring7.Main") }
@@ -77,8 +78,6 @@ tasks.register<Test>("systemTest").configure {
7778
testClassesDirs = test.output.classesDirs
7879
classpath = test.runtimeClasspath
7980

80-
outputs.upToDateWhen { false }
81-
8281
maxParallelForks = 1
8382

8483
// Cap JVM args per test

sentry-samples/sentry-samples-spring-boot-4-opentelemetry-noagent/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.spring.dependency.management)
77
alias(libs.plugins.kotlin.jvm)
88
alias(libs.plugins.kotlin.spring)
9+
id("io.sentry.systemtest")
910
}
1011

1112
group = "io.sentry.sample.spring-boot-4"
@@ -90,8 +91,6 @@ tasks.register<Test>("systemTest").configure {
9091
testClassesDirs = test.output.classesDirs
9192
classpath = test.runtimeClasspath
9293

93-
outputs.upToDateWhen { false }
94-
9594
maxParallelForks = 1
9695

9796
// Cap JVM args per test

0 commit comments

Comments
 (0)