Reputation: 20699
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'
Upvotes: 4
Views: 2315
Reputation: 9374
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.
Upvotes: 3