@@ -133,34 +133,37 @@ tasks {
133133 }
134134
135135 afterEvaluate {
136- named<Jar >(" jar" ) {
137- // Configure OSGi metadata
138- bundle {
139- // Compute import packages.
140- // Certain packages like javax.annotation.* are always optional.
141- // Modules may have additional optional packages, typically corresponding to compileOnly dependencies.
142- // Append wildcard "*" last to import any other referenced packages
143- val optionalPackages = mutableListOf (" javax.annotation" )
144- optionalPackages.addAll(otelJava.osgiOptionalPackages.get())
145- val importPackages = optionalPackages.joinToString(" ," ) { " $it .*;resolution:=optional;version=\" \$ {@}\" " } + " ,*"
146-
147- // Packages accessed via Class.forName that are not on the compile classpath cannot be made
148- // optional via Import-Package (BND cannot resolve version="${@}" for them). Instead, exclude
149- // them from Import-Package and declare them as DynamicImport-Package so OSGi does not
150- // require them at resolution time but can still wire them at runtime when available.
151- val dynamicImportPackages = otelJava.osgiDynamicImportPackages.get()
152- val negations = dynamicImportPackages.joinToString(" ," ) { " !$it " }
153- val fullImportPackages = if (negations.isNotEmpty()) " $negations ,$importPackages " else importPackages
154-
155- val bndInstructions = mutableMapOf (
156- // Once https://github.com/open-telemetry/opentelemetry-java/issues/6970 is resolved, exclude .internal packages
157- " -exportcontents" to " io.opentelemetry.*" ,
158- " Import-Package" to fullImportPackages
159- )
160- if (dynamicImportPackages.isNotEmpty()) {
161- bndInstructions[" DynamicImport-Package" ] = dynamicImportPackages.joinToString(" ," ) { " $it ,$it .*" }
136+ if (otelJava.osgiEnabled.get()) {
137+ named<Jar >(" jar" ) {
138+ // Configure OSGi metadata
139+ bundle {
140+ // Compute import packages.
141+ // Certain packages like javax.annotation.* are always optional.
142+ // Modules may have additional optional packages, typically corresponding to compileOnly dependencies.
143+ // Append wildcard "*" last to import any other referenced packages.
144+ val optionalPackages = mutableListOf (" javax.annotation" )
145+ optionalPackages.addAll(otelJava.osgiOptionalPackages.get())
146+ val importPackages = optionalPackages.joinToString(" ," ) { " $it .*;resolution:=optional;version=\" \$ {@}\" " } + " ,*"
147+
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 (
157+ // Exclude shaded internal packages from exports; they are implementation details and
158+ // should not be part of the OSGi bundle's public API surface.
159+ " -exportcontents" to " !io.opentelemetry.internal.shaded.*,io.opentelemetry.*" ,
160+ " Import-Package" to fullImportPackages
161+ )
162+ if (dynamicImportPackages.isNotEmpty()) {
163+ bndInstructions[" DynamicImport-Package" ] = dynamicImportPackages.joinToString(" ," ) { " $it ,$it .*" }
164+ }
165+ bnd(bndInstructions)
162166 }
163- bnd(bndInstructions)
164167 }
165168 }
166169 }
0 commit comments