@@ -145,24 +145,20 @@ tasks {
145145 optionalPackages.addAll(otelJava.osgiOptionalPackages.get())
146146 val importPackages = optionalPackages.joinToString(" ," ) { " $it .*;resolution:=optional;version=\" \$ {@}\" " } + " ,*"
147147
148- // Packages accessed via Class.forName that are not on the compile classpath cannot be made
149- // optional via Import-Package ( BND cannot resolve version="${@}" for them). Instead, exclude
150- // them from Import-Package and declare them as DynamicImport-Package so OSGi does not
151- // require them at resolution time but can still wire them at runtime when available .
152- val dynamicImportPackages = otelJava.osgiDynamicImportPackages .get()
153- val negations = dynamicImportPackages .joinToString(" ," ) { " ! $it " }
154- val fullImportPackages = if (negations .isNotEmpty()) " $negations ,$importPackages " else importPackages
155-
156- val bndInstructions = mutableMapOf (
148+ // Packages not on the compile classpath (e.g. due to circular dependencies) cannot use
149+ // version="${@}" since BND cannot resolve the version. Add them as optional imports without
150+ // a version constraint; they are listed before the wildcard so BND uses our explicit
151+ // instruction rather than auto-detecting them with a version .
152+ val unversionedOptionalPackages = otelJava.osgiUnversionedOptionalPackages .get()
153+ val unversionedImports = unversionedOptionalPackages .joinToString(" ," ) { " $it .*;resolution:=optional " }
154+ val fullImportPackages = if (unversionedImports .isNotEmpty()) " $unversionedImports ,$importPackages " else importPackages
155+
156+ bnd( mapOf (
157157 // Exclude shaded internal packages from exports; they are implementation details and
158158 // should not be part of the OSGi bundle's public API surface.
159159 " -exportcontents" to " !io.opentelemetry.internal.shaded.*,io.opentelemetry.*" ,
160160 " Import-Package" to fullImportPackages
161- )
162- if (dynamicImportPackages.isNotEmpty()) {
163- bndInstructions[" DynamicImport-Package" ] = dynamicImportPackages.joinToString(" ," ) { " $it .*" }
164- }
165- bnd(bndInstructions)
161+ ))
166162 }
167163 }
168164 }
0 commit comments