Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sbtosgi to generate osgi bundle as part of sbt publish task

Tags:

scala

sbt

osgi

I'm using the sbtosgi plugin to generate an OSGi bundle from an sbt build using bnd. The sbtosgi bundle provides the osgi-bundle task for generating the bundle. Using the default configuration for sbtosgi, running osgi-bundle from the sbt prompt updates the JAR to include the proper headers, but running clean package results in a JAR without OSGi headers. In Maven speak, I'm trying to do the equivalent of using maven-bundle-plugin with packaging = bundle -- i.e., the main artifact of the project should be an OSGi bundle.

Based on reading the source of sbtosgi plugin, it appears to me that the osgi-bundle task overwrites the JAR created by packageBin. I tried overriding the definition of packageBin so that it used osgi-bundle task instead of the default task:

  packageBin in Compile <<= OsgiKeys.bundle

This resulted in a cyclic reference though:

[error] Cyclic reference involving 
[error]    {file:project/*:osgi-bundle
[error]    {file:project/compile:full-classpath
[error]    {file:project/compile:exported-products
[error]    {file:project/compile:package-bin

I'm rather new to SBT and I'm not sure where to go from here. Any help would be appreciated.

like image 316
mpilquist Avatar asked Apr 18 '12 14:04

mpilquist


1 Answers

Looks like my initial suggestion via Twitter which you used does not work. Sorry for that. But luckily I had Mark Harrah sitting next to me and here comes a working solution:

packagedArtifact in (Compile, packageBin) <<= (artifact in (Compile, packageBin), OsgiKeys.bundle).identityMap

artifact in (Compile, packageBin) ~= (_.copy(`type` = "bundle"))
like image 163
Heiko Seeberger Avatar answered Sep 28 '22 08:09

Heiko Seeberger