4

I have a gradle script (editor's cut):

apply plugin:'osgi' apply plugin:'eclipse' apply plugin:'groovy' .... dependencies { .... compile 'org.codehaus.groovy:groovy-all:2.4.4' compile 'com.gmongo:gmongo:1.5' } jar { manifest { .... instruction 'Embed-Dependency', '*;scope=compile|runtime' instruction 'Embed-Transitive', 'true' instruction 'Bundle-ClassPath', '.,gmongo-1.5.jar' } from { configurations.compile.findAll{ !it.directory && it.name.startsWith( 'gmongo' ) } } } 

As soon as gmongo doesn't provide a proper bundle-manifest I must include it as a dependency.

The resulting jar structure is:

/ |..com/ |..META-INF/ |..gmongo-1.5.jar 

MANIFEST.INF:

 Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bnd-LastModified: 1461227335334 Bundle-ActivationPolicy: lazy Embed-Dependency: *;scope=compile|runtime Import-Package: com.gmongo,com.mongodb;version="[3.2,4)",groovy.lang;v ersion="[2.4,3)",....." Tool: Bnd-2.1.0.20130426-122213 Export-Package: com.mozaiq.echo;version="1.0.0";uses:="com.gmongo,groo vy.lang,javax.servlet,javax.servlet.http,org.osgi.framework" Bundle-ClassPath: .,gmongo-1.5.jar Embed-Transitive: true Created-By: 1.8.0_72 (Oracle Corporation) 

upon installing I'm getting

0 ERROR > Error occurred while trying to resolve bundle groovyecho.jar.20160426-110910406.jar!

org.osgi.framework.BundleException: Can't resolve groovyecho : package com.gmongo

What am I doing wrong?

UPDATE:

even if I unpack the gmongo.jar's classes:

jar { .... from { zipTree configurations.compile.find{ !it.directory && it.name.startsWith( 'gmongo' ) } } } 

I'm getting the same error.

SUMMARY:

instruction 'Import-Package', '!com.gmongo,*' 

worked well for un-jared class files.

To make it work on original jar file, I had to add also

instruction 'Bundle-ClassPath', '.,gmongo-1.5.jar' 

1 Answer 1

3

Well the manifest says com.gmongo must be imported. I suspect that the jar in the Bundle-Classpath is not being analyzed to see that it contains that package. So you will need to specify that the bundle does not need to import any needed packages from that embedded jar.

Import-Package: !com.gmongo,*

But given that you bundle exports com.mozaiq.echo which uses com.gmongo in its signature, you should probably export that package instead of stopping the import.

-exportcontents: com.gmongo

BTW, I don't think the Embed- instructions mean anything to the Gradle OSGi plugin which uses bnd. You can see they are just copied to the generated manifest. They are unique to the Apache Felix maven-bundle-plugin for Maven.

Sign up to request clarification or add additional context in comments.

3 Comments

bingo! the !com.gmongo worked on unzipped class files. to make it work for the mongo.jar, I had to add instruction 'Bundle-ClassPath', '.,gmongo-1.5.jar'
The Embed-Dependency instruction is used by Bnd to calculate the imports of your bundle... so you don't need the Import-Package suggested in the answer... as you're using the default Gradle osgi plugin, Bnd will not actually change the jar, just the manifest... that's why you still need to add the from instruction in the jar block to embed the jar, and add the Bundle-ClassPath instruction as well. If you want Bnd to do that, you can use the other Gradle osgi plugin by TomDmitriev.
Embed-Dependency is not something supported by bnd. It is something supported by the Apache Felix maven-bundle-plugin.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.