@@ -6,7 +6,8 @@ plugins {
66base.archivesName.set(" opentelemetry-spring-boot-autoconfigure" )
77group = " io.opentelemetry.instrumentation"
88
9- val springBootVersion = " 2.7.18" // AutoConfiguration is added in 2.7.0, but can be used with older versions
9+ val springBootVersion =
10+ " 2.7.18" // AutoConfiguration is added in 2.7.0, but can be used with older versions
1011
1112// r2dbc-proxy is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
1213// from being loaded by Spring Boot (by the presence of META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider) - even if the user doesn't want to use R2DBC.
@@ -41,7 +42,12 @@ dependencies {
4142 implementation(project(" :instrumentation-annotations-support" ))
4243 implementation(project(" :instrumentation:kafka:kafka-clients:kafka-clients-2.6:library" ))
4344 implementation(project(" :instrumentation:mongo:mongo-3.1:library" ))
44- compileOnly(project(path = " :instrumentation:r2dbc-1.0:library-instrumentation-shaded" , configuration = " shadow" ))
45+ compileOnly(
46+ project(
47+ path = " :instrumentation:r2dbc-1.0:library-instrumentation-shaded" ,
48+ configuration = " shadow"
49+ )
50+ )
4551 implementation(project(" :instrumentation:spring:spring-kafka-2.7:library" ))
4652 implementation(project(" :instrumentation:spring:spring-web:spring-web-3.1:library" ))
4753 implementation(project(" :instrumentation:spring:spring-webmvc:spring-webmvc-5.3:library" ))
@@ -107,8 +113,14 @@ dependencies {
107113 add(" javaSpring3CompileOnly" , files(sourceSets.main.get().output.classesDirs))
108114 add(" javaSpring3CompileOnly" , " org.springframework.boot:spring-boot-starter-web:3.2.4" )
109115 add(" javaSpring3CompileOnly" , " io.opentelemetry:opentelemetry-sdk-extension-autoconfigure" )
110- add(" javaSpring3CompileOnly" , project(" :instrumentation:spring:spring-web:spring-web-3.1:library" ))
111- add(" javaSpring3CompileOnly" , project(" :instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library" ))
116+ add(
117+ " javaSpring3CompileOnly" ,
118+ project(" :instrumentation:spring:spring-web:spring-web-3.1:library" )
119+ )
120+ add(
121+ " javaSpring3CompileOnly" ,
122+ project(" :instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library" )
123+ )
112124
113125 // tests don't work with spring boot 4 yet
114126 latestDepTestLibrary(" org.springframework.boot:spring-boot-starter-test:3.+" ) // documented limitation
@@ -130,8 +142,10 @@ if (latestDepTest) {
130142 }
131143}
132144
133- val testJavaVersion = gradle.startParameter.projectProperties[" testJavaVersion" ]?.let (JavaVersion ::toVersion)
134- val testSpring3 = (testJavaVersion == null || testJavaVersion.compareTo(JavaVersion .VERSION_17 ) >= 0 )
145+ val testJavaVersion =
146+ gradle.startParameter.projectProperties[" testJavaVersion" ]?.let (JavaVersion ::toVersion)
147+ val testSpring3 =
148+ (testJavaVersion == null || testJavaVersion.compareTo(JavaVersion .VERSION_17 ) >= 0 )
135149
136150testing {
137151 suites {
@@ -205,7 +219,80 @@ configurations.configureEach {
205219 }
206220}
207221
222+ val buildGraalVmReflectionJson = tasks.register(" buildGraalVmReflectionJson" ) {
223+ val targetFile = File (
224+ projectDir,
225+ " src/main/resources/META-INF/native-image/io.opentelemetry.instrumentation/opentelemetry-spring-boot/reflect-config.json"
226+ )
227+
228+ onlyIf { ! targetFile.exists() }
229+
230+ doLast {
231+ val sourcePackage =
232+ " io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model"
233+ val sourcePackagePath = sourcePackage.replace(" ." , " /" )
234+
235+ val cp = configurations.compileClasspath.get()
236+
237+ println (" Scanning classpath for OpenTelemetry Incubator SDK extension jar..." )
238+ println (cp.asPath)
239+
240+ val incubatorJar = cp
241+ .filter { it.name.contains(" opentelemetry-sdk-extension-incubator" ) && it.name.endsWith(" .jar" ) }
242+ .singleFile
243+
244+ println (" Found incubator jar: $incubatorJar " )
245+
246+ val classes = mutableListOf<String >()
247+
248+ // list contents of incubatorJar in gradle cache
249+
250+ zipTree(incubatorJar).matching {
251+ include(" $sourcePackagePath /**" )
252+ }.forEach {
253+ val path = it.path
254+
255+ println (path)
256+
257+ val className = path
258+ .substringAfter(sourcePackagePath)
259+ .removePrefix(" /" )
260+ .removeSuffix(" .class" )
261+ .replace(" /" , " ." )
262+ classes.add(" $sourcePackage .$className " )
263+ }
264+
265+ // todo remove output to console
266+ println (" Discovered ${classes.size} classes for reflection:" )
267+ println (classes)
268+
269+ // write into targetFile in json format
270+ targetFile.parentFile.mkdirs()
271+ targetFile.bufferedWriter().use { writer ->
272+ writer.write(" [\n " )
273+ classes.forEachIndexed { index, className ->
274+ writer.write(" {\n " )
275+ writer.write(" \" name\" : \" $className \" ,\n " )
276+ writer.write(" \" allDeclaredMethods\" : true,\n " )
277+ writer.write(" \" allDeclaredFields\" : true,\n " )
278+ writer.write(" \" allDeclaredConstructors\" : true\n " )
279+ writer.write(" }" )
280+ if (index < classes.size - 1 ) {
281+ writer.write(" ,\n " )
282+ } else {
283+ writer.write(" \n " )
284+ }
285+ }
286+ writer.write(" ]\n " )
287+ }
288+ }
289+ }
290+
208291tasks {
292+ compileJava {
293+ dependsOn(buildGraalVmReflectionJson)
294+ }
295+
209296 compileTestJava {
210297 options.compilerArgs.add(" -parameters" )
211298 }
0 commit comments