bnd4sbt is a BND plug-in for SBT: It enables you to create OSGi bundles for your SBT projects.
bnd4sbt is open source software licensed under the Apache 2.0 License. Just use it!
The latest releases of bnd4sbt are deployed to the Scala-Tools.org Maven repository. As this is available from every SBT project, you only have to add bnd4sbt as a plug-in to your project (see below).
If you want to go for a nightly version, you can get it from here and build it yourself using SBT:
git clone git://github.com/weiglewilczek/bnd4sbt.git cd bnd4sbt sbt publish-local
Just add the following lines to your project/plugins/Plugins.scala file:
// Repositories: Using module configs to speed up resolution => Repos must be defs! def aquteRepo = "aQute Maven Repository" at "http://www.aqute.biz/repo" lazy val aquteModuleConfig = ModuleConfiguration("biz.aQute", aquteRepo) // Dependencies lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0"
If you don’t already have such a file, you can take it from here:
class Plugins(info: ProjectInfo) extends PluginDefinition(info) { lazy val bnd4sbt = "com.weiglewilczek.bnd4sbt" % "bnd4sbt" % "1.0.0" }
Mix the com.weiglewilczek.bnd4sbt.BNDPlugin trait into your project definition.
class MyProject(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin
Now you can use the bndBundle action to create an OGSi bundle for your project. bnd4sbt also overrides the package action such that an OSGi bundle is created.
bnd4sbt offers some properties to customize the way BND will create a bundle from your project. All properties have got (hopefully) sensible defaults, e.g. the Bundle-Version will be the version of your project. Currently these properties are available:
- bndBundleSymbolicName: The value for
Bundle-SymbolicName
. Defaults to projectOrganization.projectName with duplicate subsequences removed, e.g. “a.b.c” + “c-d” => “a.b.c.d”. Recognized namespace separators are “.” and “-”. - bndBundleName: The value for
Bundle-Name
. Defaults tobndBundleSymbolicName
. - bndBundleVersion: The value for
Bundle-Version
. Defaults to this project’s version. - bndFragmentHost: The value for
Fragment-Host
, wrapped in anOption
. Defaults toNone
, i.e. no fragment is defined. - bndBundleVendor: The value for
Bundle-Vendor
, wrapped in anOption
. Defaults toNone
, i.e. no vendor is defined. - bndBundleLicense: The value for
Bundle-License
, wrapped in anOption
. Defaults toNone
, i.e. no license is defined. - bndExecutionEnvironment: The value for
Bundle-RequiredExecutionEnvironment
. Defaults to emptySet
, i.e. no execution environments are defined. - bndPrivatePackage: The value for
Private-Package
. Defaults to"%s.*".format(bndBundleSymbolicName) :: Nil
, i.e. contains the root package and all subpackages of this project. - bndExportPackage: The value for
Export-Package
. Defaults to emptySeq
, i.e. nothing is exported. - bndImportPackage: The value for
Import-Package
. Defaults to""scala.*;version=[%1$s,%1$s]".format(project.buildScalaVersion) :: "*" :: Nil
, i.e. Scala is imported only in the exact version which is used to build this project. - bndDynamicImportPackage: The value for
Dynamic-ImportPackage
. Defaults to emptySeq
, i.e. nothing is imported dynamically.
bndRequireBundle : The value forRequire-Bundle
. Defaults to emptySeq
, i.e. no bundles are required. - bndBundleActivator: The value for
Bundle-Actiavtor
, wrapped in anOption
. Defaults toNone
, i.e. no activator is defined. - bndIncludeResource: The value for
Include-Resource
. Defaults to the main resources of this project. - bndEmbedDependencies: Should the dependencies be embedded? Defaults to
false
. - bndVersionPolicy: The value for the
versionpolicy
directive, wrapped in anOption
. Defaults toNone
, i.e. no version policy is defined. - bndNoUses: Should the
nouses
directive be applied? Defaults tofalse
. - bndFileName: The file name as part of
bndOutput
. Defaults to this project’sdefaultJarName
. Attention: Better not change this, but the SBT default propertyartifactBaseName
! - bndOutput: The output path used by BND. Defaults to the
outputPath
of this project plus the value ofbndFileName
. Attention: Better not change this, but the appropriate SBT default properties! - bndClasspath: The classpath used by BND. Defaults to the
projectClasspath(Compile)
plusprovidedClasspath
of this project. Attention: Don’t mistake this for the Bundle-Classpath!
In a very simple setup you will only change the packages to be exported, e.g.:
class MyProject(info: ProjectInfo) extends DefaultProject(info) with BNDPlugin override def bndExportPackage = Seq("test;version=\"1.3\"") }