Skip to content

Commit f9dd67c

Browse files
authored
Pin latest deps for all gradle configurations (#18298)
1 parent ec99f8e commit f9dd67c

7 files changed

Lines changed: 89 additions & 37 deletions

File tree

.github/config/latest-dep-versions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@
383383
"org.glassfish:javax.faces#2.+": "2.4.0",
384384
"org.grails:grails-plugin-url-mappings#+": "6.2.3",
385385
"org.grails:grails-web-url-mappings#+": "6.2.3",
386+
"org.gwtproject:gwt-dev#+": "2.13.0",
386387
"org.gwtproject:gwt-servlet#+": "2.13.0",
388+
"org.gwtproject:gwt-user#+": "2.13.0",
387389
"org.hibernate.orm:hibernate-core#+": "7.3.3.Final",
388390
"org.hibernate.reactive:hibernate-reactive-core#+": "4.3.3.Final",
389391
"org.hibernate.reactive:hibernate-reactive-core#1.+": "1.1.9.Final",

conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,18 @@ fun getPinnedVersions(): Map<String, String> {
5454
fun lookupPinnedVersion(group: String?, name: String, version: String?): String? {
5555
if (!pinLatestDeps || group == null) return null
5656
val pinned = getPinnedVersions()
57-
return if (version == "latest.release") {
58-
pinned["$group:$name#+"]
57+
val key = if (version == "latest.release") {
58+
"$group:$name#+"
5959
} else if (version != null && version.contains("+")) {
60-
val rangeKey = "$group:$name#$version"
61-
val rangeVersion = pinned[rangeKey]
62-
if (rangeVersion != null) {
63-
rangeVersion
64-
} else {
65-
// Range-specific key is missing from the pinned versions JSON.
66-
// Do NOT fall back to the base key because it could be a different major version
67-
// (e.g. base key resolves to 4.x but the range "2.+" expects 2.x).
68-
// Run resolveLatestDepVersions to populate the missing key.
69-
throw GradleException(
70-
"Pinned version missing for range key \"$rangeKey\". " +
71-
"Run ./gradlew resolveLatestDepVersions -PtestLatestDeps=true -PresolveLatestDeps=true " +
72-
"to regenerate .github/config/latest-dep-versions.json"
73-
)
74-
}
60+
"$group:$name#$version"
7561
} else {
76-
null
62+
return null
7763
}
64+
return pinned[key] ?: throw GradleException(
65+
"Pinned version missing for key \"$key\". " +
66+
"Run ./gradlew resolveLatestDepVersions -PtestLatestDeps=true -PresolveLatestDeps=true " +
67+
"to regenerate .github/config/latest-dep-versions.json"
68+
)
7869
}
7970

8071
@CacheableRule
@@ -171,22 +162,50 @@ configurations {
171162
// "latest.release" or "+" versions (e.g. transitive deps) gets pinned to a concrete
172163
// version from the JSON file.
173164
if (otelProps.testLatestDeps) {
174-
// Only apply to test-related configurations, not build tool configurations like Zinc
175-
// (the Scala compiler). Overriding scala-library in Zinc's configuration breaks compilation.
165+
// Pinning and overrides must NOT leak into build-tool configurations like Zinc (the
166+
// Scala compiler), where forcing e.g. scala-library to a JSON-pinned version breaks
167+
// compilation. They also must not affect e.g. japicmp's `tempConfig`, which resolves
168+
// `opentelemetry-instrumentation-bom:latest.release` directly against Maven Central.
169+
// Use an allow-list of configuration names rather than a deny-list so new build-tool
170+
// configurations stay safe by default.
176171
configureEach {
177-
if (isCanBeResolved && (name.startsWith("test") || name.startsWith("latestDepTest"))) {
178-
resolutionStrategy.eachDependency {
172+
if (!isCanBeResolved) return@configureEach
173+
// `latestDepTestLibrary` overrides apply ONLY to the main test/latestDepTest
174+
// configurations. They must NOT touch `compileClasspath`, because the whole point of
175+
// `library(old)` + `latestDepTestLibrary(newRange)` is to keep the agent compiling
176+
// against the old API while testing against the new one. Forcing the override onto
177+
// compileClasspath would upgrade the compileOnly `library(...)` version and break
178+
// compilation (e.g. scala-fork-join-2.8 compiles against scala 2.8 APIs,
179+
// vertx-sql-client-4.0 against generic vertx 4.0 APIs, elasticsearch-transport-5.0
180+
// against generic ES 5.0 APIs). Overrides must also NOT touch custom JvmTestSuite
181+
// source sets (e.g. `play24Test*`, `version20Test*`, `tapirTest*`) which declare
182+
// their own explicit older versions; using `contains("test")` here would let the
183+
// main suite's `latestDepTestLibrary("...:2.5.+")` upgrade play-mvc-2.4's
184+
// `play24Test` classpath off Play 2.4. Use a strict prefix match instead.
185+
val applyOverrides = name.startsWith("test") || name.startsWith("latestDepTest")
186+
// Pinning of `latest.release`/`+` versions is applied across test-related
187+
// configurations and the main `compileClasspath`. compileClasspath is included so
188+
// that modules whose `library(...)` declarations resolve `latest.release` in latest
189+
// mode (e.g. gwt-2.0, which uses the post-2.10 `org.gwtproject` group only in latest
190+
// mode) get pinned versions on the agent's compile classpath. Pinning is safe on
191+
// compileClasspath because `lookupPinnedVersion` is a no-op for the concrete versions
192+
// declared via `library(...)`; only dynamic versions (latest.release / +) are affected.
193+
val applyPinning = pinLatestDeps &&
194+
(name.contains("test", ignoreCase = true) || name == "compileClasspath")
195+
if (!applyOverrides && !applyPinning) return@configureEach
196+
resolutionStrategy.eachDependency {
197+
if (applyOverrides) {
179198
// latestDepTestLibrary overrides take priority over pinned versions
180199
val override = latestDepTestLibraryOverrides["${requested.group}:${requested.name}"]
181200
if (override != null) {
182201
useVersion(override)
183202
return@eachDependency
184203
}
185-
if (pinLatestDeps) {
186-
val pinnedVersion = lookupPinnedVersion(requested.group, requested.name, requested.version)
187-
if (pinnedVersion != null) {
188-
useVersion(pinnedVersion)
189-
}
204+
}
205+
if (applyPinning) {
206+
val pinnedVersion = lookupPinnedVersion(requested.group, requested.name, requested.version)
207+
if (pinnedVersion != null) {
208+
useVersion(pinnedVersion)
190209
}
191210
}
192211
}

conventions/src/main/kotlin/otel.resolve-latest-dep-versions.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ tasks {
7878

7979
subprojects {
8080
configurations
81-
.filter { it.isCanBeResolved && it.name.contains("test", ignoreCase = true) && it.name.endsWith("RuntimeClasspath") }
81+
.filter {
82+
it.isCanBeResolved &&
83+
((it.name.contains("test", ignoreCase = true) && it.name.endsWith("RuntimeClasspath")) ||
84+
it.name == "compileClasspath")
85+
}
8286
.forEach { config ->
8387
config.incoming.resolutionResult.allDependencies.forEach { dep ->
8488
if (dep is org.gradle.api.artifacts.result.ResolvedDependencyResult) {

docs/contributing/writing-instrumentation.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ resolve to `latest.release` during `testLatestDeps` builds. If you use `latestDe
346346
to constrain a version range (e.g. `2.+`), you need to add an entry for that range to the
347347
JSON file.
348348

349+
> **Note:** When `-PtestLatestDeps=true` is set, every `library`/`testLibrary` dependency and
350+
> every `latestDepTestLibrary` range must have a matching entry in
351+
> `.github/config/latest-dep-versions.json`. If the entry is missing the build fails fast
352+
> rather than silently falling back to live Maven Central resolution. After adding a new
353+
> `library(...)`, `testLibrary(...)`, or ranged `latestDepTestLibrary(...)` declaration, run
354+
> the `resolveLatestDepVersions` command below to regenerate the JSON file.
355+
349356
To update the pinned versions locally:
350357

351358
```

instrumentation/gwt-2.0/javaagent/build.gradle.kts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ sourceSets {
2828
}
2929

3030
dependencies {
31-
// these are needed for compileGwt task
31+
// GWT moved from `com.google.gwt` to `org.gwtproject` in 2.10.0
3232
if (otelProps.testLatestDeps) {
33-
compileOnly("org.gwtproject:gwt-user:latest.release")
34-
compileOnly("org.gwtproject:gwt-dev:latest.release")
35-
compileOnly("org.gwtproject:gwt-servlet:latest.release")
36-
testImplementation("org.gwtproject:gwt-servlet:latest.release")
33+
library("org.gwtproject:gwt-servlet:latest.release")
34+
library("org.gwtproject:gwt-user:latest.release")
35+
library("org.gwtproject:gwt-dev:latest.release")
3736
} else {
37+
library("com.google.gwt:gwt-servlet:2.0.0")
38+
// these are needed for compileGwt task
3839
compileOnly("com.google.gwt:gwt-user:2.0.0")
3940
compileOnly("com.google.gwt:gwt-dev:2.0.0")
40-
compileOnly("com.google.gwt:gwt-servlet:2.0.0")
41-
testImplementation("com.google.gwt:gwt-servlet:2.0.0")
4241
}
4342

4443
testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))

instrumentation/kubernetes-client-7.0/javaagent/build.gradle.kts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,31 @@ dependencies {
1919
latestDepTestLibrary("io.kubernetes:client-java-api:19.+") // see test suite below
2020
}
2121

22+
val testJavaVersion = otelProps.testJavaVersion ?: JavaVersion.current()
23+
2224
testing {
2325
suites {
24-
val version20Test by registering(JvmTestSuite::class) {
26+
// version22Test reuses the same test source against `latest.release` in latest-deps mode
27+
// (currently 26.x), and against 22.0.0 otherwise, to exercise the upper end of the v20+
28+
// builder API line.
29+
val version22Test by registering(JvmTestSuite::class) {
30+
sources {
31+
java {
32+
setSrcDirs(listOf("src/version20Test/java"))
33+
}
34+
}
2535
dependencies {
26-
implementation("io.kubernetes:client-java-api:${baseVersion("20.0.0").orLatest()}")
36+
implementation("io.kubernetes:client-java-api:${baseVersion("22.0.0").orLatest()}")
37+
}
38+
targets {
39+
all {
40+
testTask.configure {
41+
// client-java-api 22.0.0+ requires Java 11+
42+
if (testJavaVersion.isJava8) {
43+
enabled = false
44+
}
45+
}
46+
}
2747
}
2848
}
2949
}

instrumentation/pekko/pekko-http-1.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ testing {
7373
implementation("com.softwaremill.sttp.tapir:tapir-pekko-http-server_$scalaVersion:${baseVersion("1.7.0").orLatest()}")
7474
if (otelProps.testLatestDeps) {
7575
implementation("org.apache.pekko:pekko-slf4j_2.13:latest.release")
76+
implementation("org.apache.pekko:pekko-actor_2.13:latest.release")
7677
}
7778
}
7879
}

0 commit comments

Comments
 (0)