Java Tips & Tricks: Building OSGi WABs with Gradle
You might spend a few hours researching different ideas on how to build OSGi WABs (OSGi-fied WAR archive for deployment web applications in OSGi containers). Here's the solution that works for me so far:
apply plugin: 'osgi'
apply plugin: 'war'
war {
manifest = osgiManifest {
instruction 'Web-ContextPath', '/context-path'
instruction 'Webapp-Context', '/context-path'
instruction 'Bundle-ClassPath', '.;/WEB-INF/classes'
classesDir = project.sourceSets.main.output.classesDir
classpath = project.configurations.runtime
}
}
Two critical elements:
- Setting
Bundle-ClassPath
not to'/WEB-INF/classes'
but'.;/WEB-INF/classes'
(notice the dot). This way bnd's Analyzer will be able to find compiled classes for imported/exported packages analysis. - Configuring
classesDir
andclass path
. osgi plugin does this by default to the mainjar
task, but nothing else, so it needs to be done explicitly.
Now, just run:
gradle war
(And yes, I am using Gradle 2.3!)
Hopefully it'll work for you!