@@ -23,12 +23,20 @@ sourceSets {
2323 setSrcDirs(listOf (" src/main/javaSpring3" ))
2424 }
2525 }
26+ create(" javaSpring4" ) {
27+ java {
28+ setSrcDirs(listOf (" src/main/javaSpring4" ))
29+ }
30+ }
2631}
2732
2833configurations {
2934 named(" javaSpring3CompileOnly" ) {
3035 extendsFrom(configurations[" compileOnly" ])
3136 }
37+ named(" javaSpring4CompileOnly" ) {
38+ extendsFrom(configurations[" compileOnly" ])
39+ }
3240}
3341
3442dependencies {
@@ -99,6 +107,9 @@ dependencies {
99107 testImplementation(" io.opentelemetry:opentelemetry-exporter-otlp" )
100108 testImplementation(" io.opentelemetry:opentelemetry-exporter-zipkin" )
101109 testImplementation(project(" :instrumentation-annotations" ))
110+ testImplementation(project(" :instrumentation:spring:spring-boot-autoconfigure:testing" ))
111+
112+ latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-micrometer-metrics:latest.release" )
102113
103114 // needed for the Spring Boot 3 support
104115 implementation(project(" :instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library" ))
@@ -110,15 +121,19 @@ dependencies {
110121 add(" javaSpring3CompileOnly" , project(" :instrumentation:spring:spring-web:spring-web-3.1:library" ))
111122 add(" javaSpring3CompileOnly" , project(" :instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library" ))
112123
113- // tests don't work with spring boot 4 yet
114- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-test:3.+" ) // documented limitation
115- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-actuator:3.+" ) // documented limitation
116- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-aop:3.+" ) // documented limitation
117- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-web:3.+" ) // documented limitation
118- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-webflux:3.+" ) // documented limitation
119- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-data-mongodb:3.+" ) // documented limitation
120- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-data-r2dbc:3.+" ) // documented limitation
121- latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-data-jdbc:3.+" ) // documented limitation
124+ // Spring Boot 4
125+ add(" javaSpring4CompileOnly" , files(sourceSets.main.get().output.classesDirs))
126+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-starter-kafka:4.0.0" )
127+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-autoconfigure:4.0.0" )
128+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-jdbc:4.0.0" )
129+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-starter-jdbc:4.0.0" )
130+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-restclient:4.0.0" )
131+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-starter-data-mongodb:4.0.0" )
132+ add(" javaSpring4CompileOnly" , " org.springframework.boot:spring-boot-starter-micrometer-metrics:4.0.0" )
133+ add(" javaSpring4CompileOnly" , project(" :instrumentation:kafka:kafka-clients:kafka-clients-2.6:library" ))
134+ add(" javaSpring4CompileOnly" , project(" :instrumentation:spring:spring-kafka-2.7:library" ))
135+ add(" javaSpring4CompileOnly" , project(" :instrumentation:mongo:mongo-3.1:library" ))
136+ add(" javaSpring4CompileOnly" , project(" :instrumentation:micrometer:micrometer-1.5:library" ))
122137}
123138
124139val latestDepTest = findProperty(" testLatestDeps" ) as Boolean
@@ -172,17 +187,62 @@ testing {
172187 }
173188 }
174189
190+ val testSpring2 by registering(JvmTestSuite ::class ) {
191+ dependencies {
192+ implementation(project())
193+ implementation(" io.opentelemetry:opentelemetry-sdk" )
194+ implementation(" io.opentelemetry:opentelemetry-sdk-testing" )
195+ implementation(" io.opentelemetry:opentelemetry-sdk-extension-autoconfigure" )
196+ implementation(project(" :instrumentation-api" ))
197+ implementation(project(" :instrumentation:micrometer:micrometer-1.5:library" ))
198+ implementation(project(" :instrumentation:spring:spring-boot-autoconfigure:testing" ))
199+ // configure Spring Boot 3.x dependencies for latest dep testing
200+ val version = if (latestDepTest) " 3.+" else springBootVersion
201+ implementation(" org.springframework.boot:spring-boot-starter-test:$version " )
202+ implementation(" org.springframework.boot:spring-boot-starter-actuator:$version " )
203+ implementation(" org.springframework.boot:spring-boot-starter-web:$version " )
204+ implementation(" org.springframework.boot:spring-boot-starter-jdbc:$version " )
205+ implementation(" org.springframework.boot:spring-boot-starter-data-r2dbc:$version " )
206+ val springKafkaVersion = if (latestDepTest) " 3.+" else " 2.9.0"
207+ implementation(" org.springframework.kafka:spring-kafka:$springKafkaVersion " )
208+ implementation(" javax.servlet:javax.servlet-api:3.1.0" )
209+ runtimeOnly(" com.h2database:h2:1.4.197" )
210+ runtimeOnly(" io.r2dbc:r2dbc-h2:1.0.0.RELEASE" )
211+ }
212+ }
213+
175214 val testSpring3 by registering(JvmTestSuite ::class ) {
176215 dependencies {
177216 implementation(project())
178- implementation(" org.springframework.boot:spring-boot-starter-web:3.2.4" )
217+ val version = if (latestDepTest) " 3.+" else " 3.2.4"
218+ implementation(" org.springframework.boot:spring-boot-starter-web:$version " )
179219 implementation(" io.opentelemetry:opentelemetry-sdk-extension-autoconfigure" )
180220 implementation(project(" :instrumentation:spring:spring-web:spring-web-3.1:library" ))
181221 implementation(project(" :instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library" ))
182222 implementation(" jakarta.servlet:jakarta.servlet-api:5.0.0" )
183- implementation(" org.springframework.boot:spring-boot-starter-test:3.2.4" ) {
184- exclude(" org.junit.vintage" , " junit-vintage-engine" )
185- }
223+ implementation(" org.springframework.boot:spring-boot-starter-test:$version " )
224+ }
225+ }
226+
227+ val testSpring4 by registering(JvmTestSuite ::class ) {
228+ dependencies {
229+ implementation(project())
230+ implementation(" io.opentelemetry:opentelemetry-sdk-extension-autoconfigure" )
231+ val version = if (latestDepTest) " latest.release" else " 4.0.0"
232+ implementation(" org.springframework.boot:spring-boot-starter-jdbc:$version " )
233+ implementation(" org.springframework.boot:spring-boot-restclient:$version " )
234+ implementation(" org.springframework.boot:spring-boot-starter-kafka:$version " )
235+ implementation(" org.springframework.boot:spring-boot-starter-actuator:$version " )
236+ implementation(" org.springframework.boot:spring-boot-starter-data-r2dbc:$version " )
237+ implementation(" org.springframework.boot:spring-boot-starter-micrometer-metrics:$version " )
238+ implementation(" io.opentelemetry:opentelemetry-sdk" )
239+ implementation(" io.opentelemetry:opentelemetry-sdk-testing" )
240+ implementation(project(" :instrumentation-api" ))
241+ implementation(project(" :instrumentation:micrometer:micrometer-1.5:library" ))
242+ implementation(project(" :instrumentation:spring:spring-boot-autoconfigure:testing" ))
243+ implementation(" org.springframework.boot:spring-boot-starter-test:$version " )
244+ runtimeOnly(" com.h2database:h2:1.4.197" )
245+ runtimeOnly(" io.r2dbc:r2dbc-h2:1.0.0.RELEASE" )
186246 }
187247 }
188248
@@ -225,22 +285,50 @@ tasks {
225285 options.release.set(17 )
226286 }
227287
288+ named<JavaCompile >(" compileTestSpring2Java" ) {
289+ sourceCompatibility = " 17"
290+ targetCompatibility = " 17"
291+ options.release.set(17 )
292+ }
293+
228294 named<JavaCompile >(" compileTestSpring3Java" ) {
229295 sourceCompatibility = " 17"
230296 targetCompatibility = " 17"
231297 options.release.set(17 )
232298 }
233299
300+ named<Test >(" testSpring2" ) {
301+ isEnabled = testSpring3
302+ }
303+
234304 named<Test >(" testSpring3" ) {
235305 isEnabled = testSpring3
236306 }
237307
308+ named<JavaCompile >(" compileJavaSpring4Java" ) {
309+ sourceCompatibility = " 17"
310+ targetCompatibility = " 17"
311+ options.release.set(17 )
312+ }
313+
314+ named<JavaCompile >(" compileTestSpring4Java" ) {
315+ sourceCompatibility = " 17"
316+ targetCompatibility = " 17"
317+ options.release.set(17 )
318+ }
319+
320+ named<Test >(" testSpring4" ) {
321+ isEnabled = testSpring3 // same condition as Spring 3 (requires Java 17+)
322+ }
323+
238324 named<Jar >(" jar" ) {
239325 from(sourceSets[" javaSpring3" ].output)
326+ from(sourceSets[" javaSpring4" ].output)
240327 }
241328
242329 named<Jar >(" sourcesJar" ) {
243330 from(sourceSets[" javaSpring3" ].java)
331+ from(sourceSets[" javaSpring4" ].java)
244332 }
245333
246334 val testStableSemconv by registering(Test ::class ) {
0 commit comments