@@ -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 {
@@ -206,7 +220,80 @@ configurations.configureEach {
206220 }
207221}
208222
223+ val buildGraalVmReflectionJson = tasks.register(" buildGraalVmReflectionJson" ) {
224+ val targetFile = File (
225+ projectDir,
226+ " src/main/resources/META-INF/native-image/io.opentelemetry.instrumentation/opentelemetry-spring-boot/reflect-config.json"
227+ )
228+
229+ onlyIf { ! targetFile.exists() }
230+
231+ doLast {
232+ val sourcePackage =
233+ " io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model"
234+ val sourcePackagePath = sourcePackage.replace(" ." , " /" )
235+
236+ val cp = configurations.compileClasspath.get()
237+
238+ println (" Scanning classpath for OpenTelemetry Incubator SDK extension jar..." )
239+ println (cp.asPath)
240+
241+ val incubatorJar = cp
242+ .filter { it.name.contains(" opentelemetry-sdk-extension-incubator" ) && it.name.endsWith(" .jar" ) }
243+ .singleFile
244+
245+ println (" Found incubator jar: $incubatorJar " )
246+
247+ val classes = mutableListOf<String >()
248+
249+ // list contents of incubatorJar in gradle cache
250+
251+ zipTree(incubatorJar).matching {
252+ include(" $sourcePackagePath /**" )
253+ }.forEach {
254+ val path = it.path
255+
256+ println (path)
257+
258+ val className = path
259+ .substringAfter(sourcePackagePath)
260+ .removePrefix(" /" )
261+ .removeSuffix(" .class" )
262+ .replace(" /" , " ." )
263+ classes.add(" $sourcePackage .$className " )
264+ }
265+
266+ // todo remove output to console
267+ println (" Discovered ${classes.size} classes for reflection:" )
268+ println (classes)
269+
270+ // write into targetFile in json format
271+ targetFile.parentFile.mkdirs()
272+ targetFile.bufferedWriter().use { writer ->
273+ writer.write(" [\n " )
274+ classes.forEachIndexed { index, className ->
275+ writer.write(" {\n " )
276+ writer.write(" \" name\" : \" $className \" ,\n " )
277+ writer.write(" \" allDeclaredMethods\" : true,\n " )
278+ writer.write(" \" allDeclaredFields\" : true,\n " )
279+ writer.write(" \" allDeclaredConstructors\" : true\n " )
280+ writer.write(" }" )
281+ if (index < classes.size - 1 ) {
282+ writer.write(" ,\n " )
283+ } else {
284+ writer.write(" \n " )
285+ }
286+ }
287+ writer.write(" ]\n " )
288+ }
289+ }
290+ }
291+
209292tasks {
293+ compileJava {
294+ dependsOn(buildGraalVmReflectionJson)
295+ }
296+
210297 compileTestJava {
211298 options.compilerArgs.add(" -parameters" )
212299 }
0 commit comments