Skip to content

Commit 5fa4655

Browse files
jbachorikclaude
andcommitted
Fix lazy task configuration and extract workaround helper
- Use lazy task resolution for javadocJar (map instead of get) - Use task matching for assembleReleaseJar (registered in afterEvaluate) - Extract javaLauncher workaround to documented helper methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4d47391 commit 5fa4655

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

build-logic/conventions/src/main/kotlin/com/datadoghq/profiler/ProfilerTestPlugin.kt

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,8 @@ class ProfilerTestPlugin : Plugin<Project> {
9393
// Use JUnit Platform
9494
task.useJUnitPlatform()
9595

96-
// Disable Gradle 9 toolchain probing (fails on musl with glibc probe binary)
97-
// Use explicit executable path instead
98-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
99-
task.javaLauncher.convention(null as org.gradle.jvm.toolchain.JavaLauncher?)
100-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
101-
task.javaLauncher.value(null as org.gradle.jvm.toolchain.JavaLauncher?)
96+
// Disable toolchain probing and set explicit executable
97+
disableToolchainProbing(task)
10298
task.setExecutable(PlatformUtils.testJavaExecutable())
10399

104100
// Standard environment variables
@@ -125,13 +121,8 @@ class ProfilerTestPlugin : Plugin<Project> {
125121
}
126122

127123
private fun configureJavaExecTask(task: JavaExec, extension: ProfilerTestExtension, project: Project) {
128-
// Disable Gradle 9 toolchain probing (fails on musl with glibc probe binary)
129-
// Use explicit executable path instead
130-
// Note: Must clear convention AND set value to prevent toolchain resolution
131-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
132-
task.javaLauncher.convention(null as org.gradle.jvm.toolchain.JavaLauncher?)
133-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
134-
task.javaLauncher.value(null as org.gradle.jvm.toolchain.JavaLauncher?)
124+
// Disable toolchain probing and set explicit executable
125+
disableToolchainProbing(task)
135126
task.setExecutable(PlatformUtils.testJavaExecutable())
136127

137128
// JVM arguments for JavaExec tasks
@@ -143,6 +134,31 @@ class ProfilerTestPlugin : Plugin<Project> {
143134
}
144135
}
145136

137+
/**
138+
* Disables Gradle 9 toolchain probing for tasks with javaLauncher property.
139+
*
140+
* Gradle 9's toolchain probing uses a glibc-compiled probe binary that fails on musl (Alpine).
141+
* This workaround clears both the convention and value to prevent any toolchain resolution.
142+
*
143+
* Must set both convention(null) AND value(null) because:
144+
* - convention(null) clears the default toolchain convention
145+
* - value(null) clears any provider-based value
146+
* Without both, Gradle may still attempt to resolve the toolchain.
147+
*/
148+
private fun disableToolchainProbing(task: org.gradle.api.tasks.JavaExec) {
149+
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
150+
task.javaLauncher.convention(null as org.gradle.jvm.toolchain.JavaLauncher?)
151+
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
152+
task.javaLauncher.value(null as org.gradle.jvm.toolchain.JavaLauncher?)
153+
}
154+
155+
private fun disableToolchainProbing(task: org.gradle.api.tasks.testing.Test) {
156+
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
157+
task.javaLauncher.convention(null as org.gradle.jvm.toolchain.JavaLauncher?)
158+
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
159+
task.javaLauncher.value(null as org.gradle.jvm.toolchain.JavaLauncher?)
160+
}
161+
146162
private fun generateMultiConfigTasks(project: Project, extension: ProfilerTestExtension) {
147163
val nativeBuildExt = project.rootProject.extensions.findByType(NativeBuildExtension::class.java)
148164
?: return // No native build extension, nothing to generate

ddprof-lib/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ val javadocJar by tasks.registering(Jar::class) {
185185
archiveBaseName.set(libraryName)
186186
archiveClassifier.set("javadoc")
187187
archiveVersion.set(componentVersion)
188-
from(tasks.javadoc.get().destinationDir)
188+
from(tasks.javadoc.map { it.destinationDir!! })
189189
}
190190

191191
// Publishing configuration
@@ -273,9 +273,10 @@ afterEvaluate {
273273
}
274274

275275
// Ensure published artifacts depend on release JAR
276+
// Note: assembleReleaseJar is registered in afterEvaluate, so use matching instead of named
276277
tasks.withType<AbstractPublishToMaven>().configureEach {
277278
if (name.contains("AssembledPublication")) {
278-
dependsOn(tasks.named("assembleReleaseJar"))
279+
dependsOn(tasks.matching { it.name == "assembleReleaseJar" })
279280
}
280281
rootProject.subprojects.forEach { subproject ->
281282
mustRunAfter(subproject.tasks.matching { it is VerificationTask })

0 commit comments

Comments
 (0)