From 9aa0d9b451d33c880ef4c33fbc1d0e6fa051c53d Mon Sep 17 00:00:00 2001 From: Kevin Wittek Date: Mon, 8 Jun 2026 08:42:40 +0000 Subject: [PATCH] fix: declare explicit task deps in shading.gradle for Gradle 8 compatibility Gradle 8 enforces strict implicit dependency validation: tasks that use the output of another task must declare an explicit dependency on it. Three groups of modules were failing: 1. test-support: test used output of jar without dependency 2. 13 JDBC modules (mariadb, mssqlserver, mysql, oceanbase, oracle-free, oracle-xe, postgresql, presto, questdb, tidb, timeplus, trino, yugabytedb): test used output of :testcontainers-jdbc-test:shadowJar without dependency 3. docs/examples junit5/redis and spock/redis: test used output of jar without dependency Root cause: shading.gradle modifies tasks.test.classpath in afterEvaluate to include shadowJar outputs, but never declared the corresponding task dependencies. Fix: after computing shadedProjects and setting test.classpath, explicitly call test.dependsOn for each project's jar and shadowJar tasks (both are needed for non-published modules where both tasks write the same filename), and also for shadowJar of testImplementation project dependencies whose primary artifact is produced by shadowJar (classifier=null). --- gradle/shading.gradle | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gradle/shading.gradle b/gradle/shading.gradle index 88f25cc3f22..9dfd0edc528 100644 --- a/gradle/shading.gradle +++ b/gradle/shading.gradle @@ -57,10 +57,34 @@ project.afterEvaluate { } // Add shaded JARs first - tasks.test.classpath = findShadedProjects(project) - .plus(project) + def shadedProjects = findShadedProjects(project).plus(project) + tasks.test.classpath = shadedProjects .sum { it.tasks.findByName("shadowJar").outputs.files } .plus(sourceSets.test.runtimeClasspath) + + // Gradle 8: declare explicit task dependencies for all jar/shadowJar tasks whose outputs + // are added to the test classpath, to satisfy strict implicit dependency validation. + // Both jar and shadowJar must be declared because non-published modules (e.g. test-support, + // docs examples) do not set jar.archiveClassifier, so both tasks write the same filename. + shadedProjects.each { p -> + def shadowJarTask = p.tasks.findByName("shadowJar") + if (shadowJarTask != null) { + tasks.test.dependsOn(shadowJarTask) + } + def jarTask = p.tasks.findByName("jar") + if (jarTask != null) { + tasks.test.dependsOn(jarTask) + } + } + + // Also declare explicit dependency on shadowJar tasks from testImplementation project + // dependencies, since their shadowJar output (classifier=null) is the resolved artifact. + configurations.testImplementation.dependencies.withType(ProjectDependency).each { dep -> + def shadowJarTask = dep.dependencyProject.tasks.findByName("shadowJar") + if (shadowJarTask != null) { + tasks.test.dependsOn(shadowJarTask) + } + } } static Set findShadedProjects(Project project) {