Skip to content

Add native OSGi bundle metadata to published jars#498

Open
royteeuwen wants to merge 2 commits into
open-telemetry:mainfrom
royteeuwen:osgi-support
Open

Add native OSGi bundle metadata to published jars#498
royteeuwen wants to merge 2 commits into
open-telemetry:mainfrom
royteeuwen:osgi-support

Conversation

@royteeuwen

Copy link
Copy Markdown

Description

Closes #494

Publishes the semconv and semconv-incubating jars with OSGi bundle metadata so they can be consumed directly in OSGi containers, without external re-wrapping (e.g. hand-maintained wrapper bundles).

This mirrors the OSGi support recently added to opentelemetry-java: the bnd Gradle plugin (biz.aQute.bnd.builder) is wired into the shared otel.java-conventions plugin and driven by OtelJavaExtension. Since the semconv modules have no SPI / ServiceLoader needs, the configuration is a trimmed-down version of the upstream one (no ServiceLoader mediator capabilities).

Changes

  • buildSrc/build.gradle.kts — add the biz.aQute.bnd:biz.aQute.bnd.gradle plugin dependency.
  • OtelJavaExtension — add osgiEnabled (default true) and osgiOptionalPackages knobs.
  • otel.java-conventions.gradle.kts — apply biz.aQute.bnd.builder, make archives reproducible, and configure the main jar task's bundle with -exportcontents: io.opentelemetry.* plus an auto-detecting Import-Package. Both modules (and any future module) are bundled automatically; the -sources/-javadoc jars are left plain.

Generated manifest (excerpt)

opentelemetry-semconv:

Bundle-SymbolicName: opentelemetry-semconv
Export-Package: io.opentelemetry.semconv;version="1.41.1";uses:="io.opentelemetry.api.common"
Import-Package: io.opentelemetry.api.common,java.lang,...
Automatic-Module-Name: io.opentelemetry.semconv

opentelemetry-semconv-incubating:

Bundle-SymbolicName: opentelemetry-semconv-incubating
Export-Package: io.opentelemetry.semconv.incubating;version="1.41.1";uses:="io.opentelemetry.api.common,io.opentelemetry.semconv"
Import-Package: io.opentelemetry.api.common,io.opentelemetry.semconv;version="[1.41,2)",...

Testing

  • ./gradlew build passes (unit tests, checkstyle, japicmp, animal-sniffer).
  • Verified the main jars carry the OSGi headers and the -sources/-javadoc jars remain plain.

Wire the bnd Gradle plugin into the shared otel.java-conventions plugin
so the semconv and semconv-incubating jars are published with OSGi
manifest headers (Bundle-SymbolicName, Export-Package, Import-Package).
This lets the artifacts be consumed directly in OSGi containers without
external re-wrapping.

Fixes open-telemetry#494
@royteeuwen royteeuwen requested review from a team as code owners June 14, 2026 17:46
@royteeuwen

Copy link
Copy Markdown
Author

@trask anything I can do to get this mergeable?

Copilot AI review requested due to automatic review settings July 14, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds native OSGi bundle metadata to the published semconv and semconv-incubating JARs by wiring the Bnd Gradle plugin into the shared otel.java-conventions build logic, enabling direct consumption in OSGi containers without wrapper bundles.

Changes:

  • Adds the biz.aQute.bnd.builder plugin to the shared otel.java-conventions precompiled script plugin and configures the main jar task to emit OSGi headers (exporting io.opentelemetry.* and auto-detecting imports).
  • Introduces osgiEnabled (default true) and osgiOptionalPackages extension knobs to control/augment OSGi import behavior.
  • Adds the Bnd Gradle plugin dependency to buildSrc and enables reproducible archive settings for JAR outputs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts Applies/configures Bnd for OSGi metadata on the main jar and enables reproducible archive output.
buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt Adds extension properties to control enabling OSGi metadata and optional import packages.
buildSrc/build.gradle.kts Adds the Bnd Gradle plugin dependency to the build logic classpath.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@trask trask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test?

or, related to open-telemetry/opentelemetry-java-instrumentation#18995, is there maybe another way / tool we could validate a jar for osgi compliance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSGi support

3 participants