Skip to content

Commit 1562192

Browse files
bric3claude
andcommitted
chore(build-logic): default smokeTestApp to JDK 21 daemon + Gradle 8.14.5
Set conventions on `smokeTestApp`: - `gradleVersion` defaults to `"8.14.5"` (Gradle 8 last release; pinned because Spring Boot plugin pre-3.5 calls `Configuration.getUploadTaskName()`, removed in Gradle 9). - `javaLauncher` defaults to a JDK 21 toolchain (the version the root build requires for its own Gradle 9 migration; standardising the nested daemon on the same JDK avoids requiring an extra toolchain on dev machines and CI runners). Consumers that need a different JDK or Gradle version still override explicitly. The inner build script is responsible for pinning the produced bytecode level (`java { sourceCompatibility = JavaVersion.VERSION_1_8 }` or similar) — Gradle adds `--release N` automatically when source/target differs from the daemon JVM. `JavaToolchainService` is now injected into the extension; this works in any project where a `java*` (or related) plugin is applied. Smoke-test modules already apply `gradle/java.gradle`, which applies `java`, so the convention resolves on first read. Public defaults exposed as `DEFAULT_NESTED_GRADLE_VERSION` and `DEFAULT_NESTED_JAVA_VERSION` constants so the values are discoverable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a5824d8 commit 1562192

3 files changed

Lines changed: 71 additions & 11 deletions

File tree

build-logic/smoke-test/src/main/kotlin/datadog/buildlogic/smoketest/NestedGradleBuild.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import org.gradle.api.tasks.OutputDirectory
1818
import org.gradle.api.tasks.PathSensitive
1919
import org.gradle.api.tasks.PathSensitivity
2020
import org.gradle.api.tasks.TaskAction
21+
import org.gradle.jvm.toolchain.JavaLanguageVersion
2122
import org.gradle.jvm.toolchain.JavaLauncher
23+
import org.gradle.jvm.toolchain.JavaToolchainService
2224
import org.gradle.tooling.GradleConnector
2325
import javax.inject.Inject
2426

@@ -34,8 +36,19 @@ import javax.inject.Inject
3436
* `-P<propertyName>=<absolute-path>` and tracked as a task input so the nested build re-runs
3537
* when the upstream jar changes.
3638
*/
37-
abstract class NestedGradleBuild @Inject constructor(private val objects: ObjectFactory) :
38-
DefaultTask() {
39+
abstract class NestedGradleBuild @Inject constructor(
40+
private val objects: ObjectFactory,
41+
javaToolchains: JavaToolchainService,
42+
) : DefaultTask() {
43+
44+
init {
45+
gradleVersion.convention(DEFAULT_NESTED_GRADLE_VERSION)
46+
javaLauncher.convention(
47+
javaToolchains.launcherFor {
48+
languageVersion.set(JavaLanguageVersion.of(DEFAULT_NESTED_JAVA_VERSION))
49+
},
50+
)
51+
}
3952

4053
@get:Internal
4154
abstract val applicationDir: DirectoryProperty

build-logic/smoke-test/src/main/kotlin/datadog/buildlogic/smoketest/SmokeTestAppExtension.kt

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import org.gradle.api.provider.Property
1111
import org.gradle.api.provider.Provider
1212
import org.gradle.api.tasks.TaskProvider
1313
import org.gradle.api.tasks.testing.Test
14+
import org.gradle.jvm.toolchain.JavaLanguageVersion
1415
import org.gradle.jvm.toolchain.JavaLauncher
16+
import org.gradle.jvm.toolchain.JavaToolchainService
1517
import org.gradle.process.CommandLineArgumentProvider
1618
import java.util.Locale
1719
import javax.inject.Inject
@@ -23,12 +25,24 @@ import javax.inject.Inject
2325
* stays unconfigured, the plugin is a no-op and consumers can register [NestedGradleBuild]
2426
* directly.
2527
*/
26-
abstract class SmokeTestAppExtension @Inject constructor(private val project: Project) {
28+
abstract class SmokeTestAppExtension @Inject constructor(
29+
private val project: Project,
30+
javaToolchains: JavaToolchainService,
31+
) {
2732

28-
/** Gradle version used by the nested daemon. Defaults to the root build's version. */
33+
/**
34+
* Gradle version used by the nested daemon. Defaults to [DEFAULT_NESTED_GRADLE_VERSION] —
35+
* the version pinned for smoke-test applications whose Spring Boot plugin is incompatible
36+
* with Gradle 9.
37+
*/
2938
abstract val gradleVersion: Property<String>
3039

31-
/** JDK used by the nested daemon. Required when calling [application]. */
40+
/**
41+
* JDK used by the nested daemon. Defaults to a [DEFAULT_NESTED_JAVA_VERSION] toolchain;
42+
* override to pin a different JDK if the nested application's plugin chain requires it.
43+
* The inner build script is responsible for pinning the produced bytecode level (e.g.
44+
* `java { sourceCompatibility = JavaVersion.VERSION_1_8 }`).
45+
*/
3246
abstract val javaLauncher: Property<JavaLauncher>
3347

3448
/** Directory containing the nested project's `settings.gradle` + sources. */
@@ -45,7 +59,12 @@ abstract class SmokeTestAppExtension @Inject constructor(private val project: Pr
4559
init {
4660
applicationDir.convention(project.layout.projectDirectory.dir("application"))
4761
applicationBuildDir.convention(project.layout.buildDirectory.dir("application"))
48-
gradleVersion.convention(project.gradle.gradleVersion)
62+
gradleVersion.convention(DEFAULT_NESTED_GRADLE_VERSION)
63+
javaLauncher.convention(
64+
javaToolchains.launcherFor {
65+
languageVersion.set(JavaLanguageVersion.of(DEFAULT_NESTED_JAVA_VERSION))
66+
},
67+
)
4968
}
5069

5170
/**
@@ -54,9 +73,6 @@ abstract class SmokeTestAppExtension @Inject constructor(private val project: Pr
5473
* register [NestedGradleBuild] manually can leave [application] uncalled.
5574
*/
5675
fun application(action: Action<ApplicationSpec>) {
57-
require(javaLauncher.isPresent) {
58-
"smokeTestApp.javaLauncher must be set before configuring application { ... }"
59-
}
6076
val spec = project.objects.newInstance(ApplicationSpec::class.java)
6177
action.execute(spec)
6278
val taskName = requireNotNull(spec.taskName.orNull) {
@@ -167,6 +183,21 @@ abstract class ApplicationSpec @Inject constructor() {
167183
abstract val additionalSystemProperties: MapProperty<String, String>
168184
}
169185

186+
/**
187+
* Default Gradle distribution version for the nested daemon. Pinned to a Gradle 8 release
188+
* because the Spring Boot Gradle plugin pre-3.5.0 calls `Configuration.getUploadTaskName()`,
189+
* removed in Gradle 9.
190+
*/
191+
const val DEFAULT_NESTED_GRADLE_VERSION = "8.14.5"
192+
193+
/**
194+
* Default JDK language version for the nested daemon. JDK 21 is the version the root build
195+
* requires for Gradle 9; standardising the nested daemon on the same JDK avoids pulling a
196+
* second toolchain onto dev machines and CI runners. Inner build scripts cross-compile down
197+
* to their actual bytecode target via `java { sourceCompatibility = ... }`.
198+
*/
199+
const val DEFAULT_NESTED_JAVA_VERSION = 21
200+
170201
private class SmokeTestArgProvider(
171202
private val sysProperty: String,
172203
private val artifact: Provider<RegularFile>,

build-logic/smoke-test/src/test/kotlin/datadog/buildlogic/smoketest/SmokeTestAppPluginTest.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package datadog.buildlogic.smoketest
22

33
import org.assertj.core.api.Assertions.assertThat
4+
import org.gradle.api.plugins.JavaPlugin
5+
import org.gradle.jvm.toolchain.JavaLanguageVersion
46
import org.gradle.testfixtures.ProjectBuilder
57
import org.junit.jupiter.api.Test
68

@@ -54,12 +56,26 @@ class SmokeTestAppPluginTest {
5456
}
5557

5658
@Test
57-
fun `extension defaults gradleVersion to the host build's version`() {
59+
fun `extension defaults gradleVersion to the smoke-test pinned version`() {
5860
val project = ProjectBuilder.builder().build()
5961
project.plugins.apply("dd-trace-java.smoke-test-app")
6062

6163
val extension = project.extensions.getByType(SmokeTestAppExtension::class.java)
6264

63-
assertThat(extension.gradleVersion.get()).isEqualTo(project.gradle.gradleVersion)
65+
assertThat(extension.gradleVersion.get()).isEqualTo(DEFAULT_NESTED_GRADLE_VERSION)
66+
}
67+
68+
@Test
69+
fun `extension defaults javaLauncher to a JDK 21 toolchain`() {
70+
// JavaToolchainService is contributed by the `java-base` plugin; apply something that
71+
// pulls it in so ProjectBuilder can resolve the convention.
72+
val project = ProjectBuilder.builder().build()
73+
project.plugins.apply(JavaPlugin::class.java)
74+
project.plugins.apply("dd-trace-java.smoke-test-app")
75+
76+
val extension = project.extensions.getByType(SmokeTestAppExtension::class.java)
77+
78+
assertThat(extension.javaLauncher.get().metadata.languageVersion)
79+
.isEqualTo(JavaLanguageVersion.of(DEFAULT_NESTED_JAVA_VERSION))
6480
}
6581
}

0 commit comments

Comments
 (0)