# How to use Gradle to repackage a jar as an OSGi bundle?

**URL:** <https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539>\
**Category:** Old Forum Archive\
**Created:** [February 4, 2013, 2:50pm UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539 "2013-02-04T14:50:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbelling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mbelling/32/565_2.png) [@mbelling](https://discuss.gradle.org/u/mbelling)\
**Post date:** [February 4, 2013, 2:50pm UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/1 "2013-02-04T14:50:00Z")

</div>

I am working on a project that will be using OSGi. We depend on a few third party libraries that we would like to repackage as OSGi bundles. Is there a built in way in Gradle to take a non-OSGi jar, and repackage it with the OSGi headers in the manifest?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 5, 2013, 11:06am UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/2 "2013-02-05T11:06:00Z")

</div>

Hi,

There’s currently nothing built in specifically. It’s pretty easy to repackage a jar with a new manifest though:

```gradle
apply plugin: "osgi"
  task fooJar(type: Jar) {
    from zipTree("path/to/some.jar")
    manifest = osgiManifest {
        instruction 'Bundle-Vendor', 'MyCompany'
        }
}

```

The api for the osgiManifest method is: [http://www.gradle.org/docs/current/javadoc/org/gradle/api/plugins/osgi/OsgiManifest.html](http://www.gradle.org/docs/current/javadoc/org/gradle/api/plugins/osgi/OsgiManifest.html)

---

<div class="post-metadata">

**Author:** ![mbelling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mbelling/32/565_2.png) [@mbelling](https://discuss.gradle.org/u/mbelling)\
**Post date:** [February 5, 2013, 5:51pm UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/3 "2013-02-05T17:51:00Z")

</div>

I think this should get me enough of what I need it for. Thank you.

---

<div class="post-metadata">

**Author:** ![mbelling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mbelling/32/565_2.png) [@mbelling](https://discuss.gradle.org/u/mbelling)\
**Post date:** [February 5, 2013, 7:59pm UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/4 "2013-02-05T19:59:00Z")

</div>

I take that back, something is not quite right:

```gradle
task createOsgiBundle(type:Jar) {
    from zipTree( '/path/to/my.jar' )
    manifest = osgiManifest {
        instruction 'Bundle-Vendor', 'VendorName'
    }
}

```

Running this task causes the following exception:

[https://gist.github.com/anonymous/4717044](https://gist.github.com/anonymous/4717044)

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 6, 2013, 10:05am UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/5 "2013-02-06T10:05:00Z")

</div>

If you can provide a complete project that I can play with I can help further.

---

<div class="post-metadata">

**Author:** ![Martin2](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Martin2](https://discuss.gradle.org/u/Martin2)\
**Post date:** [March 7, 2013, 5:39pm UTC](https://discuss.gradle.org/t/how-to-use-gradle-to-repackage-a-jar-as-an-osgi-bundle/6539/6 "2013-03-07T17:39:00Z")

</div>

What’s about license problems, is it allways allowed to repackage a third party library?
