https://github.com/sbt/sbt-osgi
sbt plugin for creating OSGi bundles
https://github.com/sbt/sbt-osgi
osgi sbt sbt-plugin
Last synced: about 1 year ago
JSON representation
sbt plugin for creating OSGi bundles
- Host: GitHub
- URL: https://github.com/sbt/sbt-osgi
- Owner: sbt
- License: apache-2.0
- Created: 2012-10-22T20:31:46.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T09:24:23.000Z (over 1 year ago)
- Last Synced: 2025-03-30T03:08:57.476Z (about 1 year ago)
- Topics: osgi, sbt, sbt-plugin
- Language: Scala
- Size: 380 KB
- Stars: 47
- Watchers: 14
- Forks: 43
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sbt-osgi
========
[](https://github.com/sbt/sbt-osgi/actions/workflows/ci.yml)
Plugin for [sbt](http://www.scala-sbt.org) to create [OSGi](http://www.osgi.org/) bundles.
Installing sbt-osgi
-------------------
sbt-osgi is a plugin for sbt. In order to install sbt, please refer to the sbt [1.x](https://www.scala-sbt.org/1.x/docs/Setup.html)). Please make sure that you are using a suitable version of sbt:
- sbt-osgi 0.9.{4-x} -> sbt 1.6.2+ (older versions of sbt may work but 1.6.2+ supports all JDK LTS versions)
As sbt-osgi is a plugin for sbt, it is installed like any other sbt plugin, that is by mere configuration: just add sbt-osgi to your global or local plugin definition. Global plugins are defined in `~/.sbt//plugins/plugins.sbt` and local plugins are defined in `project/plugins.sbt` in your project.
In order to add sbt-osgi as a plugin, just add the below setting to the relevant plugin definition, paying attention to blank lines between settings:
```sbt
// Other stuff
addSbtPlugin("com.github.sbt" % "sbt-osgi" % "0.9.11")
```
If you want to use the latest and greatest features, you can instead have sbt depend on and locally build the current source snapshot by adding the following to your plugin definition file.
Example `/project/plugins.sbt`:
```sbt
lazy val plugins = (project in file("."))
.dependsOn(sbtOsgi)
// Other stuff
def sbtOsgi = uri("git://github.com/sbt/sbt-osgi.git")
```
Using sbt-osgi
---------------
#### Version 0.8.0 and above
As, since version `0.8.0`, sbt-osgi uses the sbt 0.13.5 *Autoplugin* feature, it can be enabled for individual projects like any other sbt Autoplugin. For more information on enabling and disabling plugins, refer to the [sbt plugins tutorial](http://www.scala-sbt.org/release/tutorial/Using-Plugins.html#Enabling+and+disabling+auto+plugins).
Example `/build.sbt`:
```sbt
enablePlugins(SbtOsgi)
```
To also override the default publish behaviour, also add the `osgiSettings` settings to your project via your preferred method.
Example `/build.sbt`:
```sbt
// Other settings
osgiSettings
```
#### Version 0.7.0 and below
Add the below line to your sbt build definition, which adds the task `osgiBundle` which creates an OSGi bundle for your project and also changes the `publish` task to publish an OSGi bundle instead of a raw JAR archive. Again, pay attention to the blank line between settings:
```sbt
// Other stuff
osgiSettings
```
If you just want `osgiBundle`, i.e. don't want to change the behavior of `publish`:
```
// Other stuff
defaultOsgiSettings
```
Settings
--------
sbt-osgi can be configured with the following settings:
- `bundleActivator`: value for `Bundle-Activator` header, default is `None`
- `bundleRequiredExecutionEnvironment`: value for `Bundle-RequiredExecutionEnvironment` header, default is an empty string.
- `bundleSymbolicName`: value for `Bundle-SymbolicName` header, default is `organization` plus `name`
- `bundleVersion`: value for `Bundle-Version` header, default is `version`
- `dynamicImportPackage`: values for `Dynamic-ImportPackage` header, default is the empty sequence
- `exportPackage`: values for `Export-Package` header, default is the empty sequence
- `importPackage`: values for `Import-Package` header, default is `*`
- `fragmentHost`: value for `Fragment-Host` header, default is `None`
- `privatePackage`: values for `Private-Package` header, default is `OsgiKeys.bundleSymbolicName` plus `.*`
- `requireBundle`: values for `Require-Bundle` header, default is the empty sequence
- `additionalHeaders`: map of additional headers to be passed to BND, default is the empty sequence
- `embeddedJars`: list of dependencies to embed inside the bundle which are automatically added to `Bundle-Classpath`
- `explodedJars`: list of jarfiles to explode into the bundle
- `requireCapability`: value for `Require-Capability` header, defaults to `osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=*PROJECT JAVAC VERSION*))"`
- `failOnUndecidedPackage`: allows failing the build when a package is neither exported nor private (instead of silently dropping it), `false` by default to be compatible with previous behaviour
Example `build.sbt`:
```sbt
organization := "com.github.sbt"
name := "osgi.demo"
version := "1.0.0"
enablePlugins(SbtOsgi)
libraryDependencies += "org.osgi" % "org.osgi.core" % "4.3.0" % "provided"
osgiSettings
OsgiKeys.exportPackage := Seq("com.github.sbt.osgidemo")
OsgiKeys.bundleActivator := Option("com.github.sbt.osgidemo.internal.Activator")
```
License
-------
This code is open source software licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).