Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

BND plugin for SBT

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 project
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.textile
README.textile

bnd4sbt

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!

Getting bnd4sbt

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

Adding bnd4sbt as a plug-in to your project

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"
}

Using bnd4sbt

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 to bndBundleSymbolicName.
  • bndBundleVersion: The value for Bundle-Version. Defaults to this project’s version.
  • bndFragmentHost: The value for Fragment-Host, wrapped in an Option. Defaults to None, i.e. no fragment is defined.
  • bndBundleVendor: The value for Bundle-Vendor, wrapped in an Option. Defaults to None, i.e. no vendor is defined.
  • bndBundleLicense: The value for Bundle-License, wrapped in an Option. Defaults to None, i.e. no license is defined.
  • bndExecutionEnvironment: The value for Bundle-RequiredExecutionEnvironment. Defaults to empty Set, 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 empty Seq, 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 empty Seq, i.e. nothing is imported dynamically.
    bndRequireBundle : The value for Require-Bundle. Defaults to empty Seq, i.e. no bundles are required.
  • bndBundleActivator: The value for Bundle-Actiavtor, wrapped in an Option. Defaults to None, 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 an Option. Defaults to None, i.e. no version policy is defined.
  • bndNoUses: Should the nouses directive be applied? Defaults to false.
  • bndFileName: The file name as part of bndOutput. Defaults to this project’s defaultJarName. Attention: Better not change this, but the SBT default property artifactBaseName!
  • bndOutput: The output path used by BND. Defaults to the outputPath of this project plus the value of bndFileName. Attention: Better not change this, but the appropriate SBT default properties!
  • bndClasspath: The classpath used by BND. Defaults to the projectClasspath(Compile) plus providedClasspath 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\"")
}
Something went wrong with that request. Please try again.