Skip to content

Commit f41478c

Browse files
runningcodeclaude
andcommitted
test(spring): Clean up the Spring Boot matrix plugin's Gradle configuration
- compileJavaBoot<version> no longer realizes compileJava while it's configured. It links compileJava's release lazily, takes the annotation processors from the source set, and leaves the toolchain to the Java plugin's default for every JavaCompile. - The matrix classpaths extend implementation and compileOnly or runtimeOnly by name. Copying the base classpath's parents depended on what had been added to it by the time the block ran. - They're created with configurations.resolvable(), so they can't be consumed or declared on. Every matrix configuration resolves the same as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8eb9829 commit f41478c

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

‎build-logic/src/main/kotlin/io/sentry/gradle/SpringBootMatrixPlugin.kt‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ abstract class SpringBootMatrixExtension @Inject constructor(private val project
5555
}
5656

5757
val oldest = versions.first()
58+
val main = sourceSet("main")
5859
val compileClasspath = classpath("main", oldest, compile = true)
60+
val compileJava = project.tasks.named("compileJava", JavaCompile::class.java)
5961
val compileOldest =
6062
project.tasks.register("compileJava${suffix(oldest)}", JavaCompile::class.java) {
6163
description = "Compiles the main Java sources against Spring Boot $oldest."
6264
group = LifecycleBasePlugin.VERIFICATION_GROUP
63-
val compileJava = project.tasks.named("compileJava", JavaCompile::class.java).get()
64-
source = sourceSet("main").java
65+
source = main.java
6566
classpath = compileClasspath
66-
destinationDirectory.set(project.layout.buildDirectory.dir("classes/java/main${suffix(oldest)}"))
67-
javaCompiler.set(compileJava.javaCompiler)
68-
options.release.set(compileJava.options.release)
69-
options.annotationProcessorPath = compileJava.options.annotationProcessorPath
67+
destinationDirectory.set(
68+
project.layout.buildDirectory.dir("classes/java/main${suffix(oldest)}")
69+
)
70+
options.release.set(compileJava.flatMap { it.options.release })
71+
options.annotationProcessorPath = main.annotationProcessorPath
7072
}
7173
project.tasks.named(aggregateName(oldest)) { dependsOn(compileOldest) }
7274
}
@@ -104,20 +106,27 @@ abstract class SpringBootMatrixExtension @Inject constructor(private val project
104106
val base =
105107
if (compile) sources.compileClasspathConfigurationName
106108
else sources.runtimeClasspathConfigurationName
109+
val only =
110+
if (compile) sources.compileOnlyConfigurationName else sources.runtimeOnlyConfigurationName
107111
val name = "$sourceSet${suffix(version)}${if (compile) "Compile" else "Runtime"}Classpath"
108112
val configurations = project.configurations
109113
return configurations.findByName(name)
110-
?: configurations.create(name) {
111-
isCanBeConsumed = false
112-
val baseConfiguration = configurations.getByName(base)
113-
extendsFrom(*baseConfiguration.extendsFrom.toTypedArray())
114-
attributes.addAllLater(baseConfiguration.attributes)
115-
// What setting the version in the catalog does: every Spring Boot artifact, the BOM
116-
// included, is in this group. Libraries pinned to their own version still win conflicts.
117-
resolutionStrategy.eachDependency {
118-
if (requested.group == "org.springframework.boot") useVersion(version)
114+
?: configurations
115+
.resolvable(name) {
116+
// The base classpath's parents by name, since copying its extendsFrom would depend on
117+
// what has been added to it by the time this runs.
118+
extendsFrom(
119+
configurations.getByName(sources.implementationConfigurationName),
120+
configurations.getByName(only),
121+
)
122+
attributes.addAllLater(configurations.getByName(base).attributes)
123+
// What setting the version in the catalog does: every Spring Boot artifact, the BOM
124+
// included, is in this group. Libraries pinned to their own version still win conflicts.
125+
resolutionStrategy.eachDependency {
126+
if (requested.group == "org.springframework.boot") useVersion(version)
127+
}
119128
}
120-
}
129+
.get()
121130
}
122131

123132
private fun sourceSet(name: String) =

0 commit comments

Comments
 (0)