Skip to content

Commit 3739855

Browse files
committed
Cleanup bnd warnings by disabling on test modules
1 parent a4340f7 commit 3739855

14 files changed

Lines changed: 47 additions & 27 deletions

File tree

all/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
description = "OpenTelemetry All"
66
otelJava.moduleName.set("io.opentelemetry.all")
7+
otelJava.osgiEnabled.set(false)
78

89
// Skip ossIndexAudit on test module
910
tasks.named("ossIndexAudit") {

animal-sniffer-signature/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88

99
description = "Build tool to generate the Animal Sniffer Android signature"
1010
otelJava.moduleName.set("io.opentelemetry.internal.animalsniffer")
11+
otelJava.osgiEnabled.set(false)
1112

1213
val signatureJar = configurations.create("signatureJar") {
1314
isCanBeConsumed = false

api/testing-internal/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
description = "OpenTelemetry API Testing (Internal)"
66
otelJava.moduleName.set("io.opentelemetry.api.testing.internal")
7+
otelJava.osgiEnabled.set(false)
78

89
dependencies {
910
api(project(":api:all"))

buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import org.gradle.api.provider.Property
1212
abstract class OtelJavaExtension {
1313
abstract val moduleName: Property<String>
1414

15+
// Set to false for modules that are not OSGi bundles (e.g. test helpers, build tooling,
16+
// aggregators). Skips BND bundle metadata generation entirely.
17+
abstract val osgiEnabled: Property<Boolean>
18+
1519
abstract val osgiOptionalPackages: ListProperty<String>
1620

1721
// Packages accessed via Class.forName that are not on the compile classpath (e.g. due to
@@ -24,6 +28,7 @@ abstract class OtelJavaExtension {
2428

2529
init {
2630
minJavaVersionSupported.convention(JavaVersion.VERSION_1_8)
31+
osgiEnabled.convention(true)
2732
osgiOptionalPackages.convention(emptyList<String>())
2833
osgiDynamicImportPackages.convention(emptyList<String>())
2934
}

buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

exporters/common/compile-stub/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ plugins {
44

55
description = "OpenTelemetry Exporter Compile Stub"
66
otelJava.moduleName.set("io.opentelemetry.exporter.internal.compile-stub")
7+
otelJava.osgiEnabled.set(false)

integration-tests/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
description = "OpenTelemetry Integration Tests"
66
otelJava.moduleName.set("io.opentelemetry.integration.tests")
7+
otelJava.osgiEnabled.set(false)
78

89
dependencies {
910
testImplementation(project(":sdk:all"))

integration-tests/graal-incubating/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77

88
description = "OpenTelemetry Graal Integration Tests (Incubating)"
99
otelJava.moduleName.set("io.opentelemetry.graal.integration.tests.incubating")
10+
otelJava.osgiEnabled.set(false)
1011
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_17)
1112

1213
sourceSets {

integration-tests/graal/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77

88
description = "OpenTelemetry Graal Integration Tests"
99
otelJava.moduleName.set("io.opentelemetry.graal.integration.tests")
10+
otelJava.osgiEnabled.set(false)
1011
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_17)
1112

1213
sourceSets {

integration-tests/otlp/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
description = "OTLP Exporter Integration Tests"
66
otelJava.moduleName.set("io.opentelemetry.integration.tests.otlp")
7+
otelJava.osgiEnabled.set(false)
78

89
dependencies {
910
api("org.testcontainers:testcontainers-junit-jupiter")

0 commit comments

Comments
 (0)