Using maven-bundle-plugin with the maven-shade-plugin
maven, maven-bundle-plugin, maven-shade-plugin, osgi
Solution
Another option is to dump maven bundle plugin altogether and use Maven Shade Plugin ManifestResourceTransformer to add the desired OSGI metadata to the manifest.
Take a look at xbean-asm-shaded/pom.xml for a example.
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>
org.apache.xbean.asm;org.modelmapper.builder; ...
</Export-Package>
<Import-Package>*</Import-Package>
<Private-Package>org.modelmapper.internal ...</Private-Package>
</manifestEntries>
</transformer>
Problem
I'm using the maven-shade-plugin to relocate some packages during the package phase of my build. I'm also using the maven-bundle-plugin to generate a manifest. The problem is the bundle plugin runs before the shade plugin (during the process-classes phase), and doesn't include any of my shaded packages in the generated manifest's exports. How can I get these two plugins to play nice with each other, so that my relocated packages are treated like any other package by the bundle plugin? -- By request, the Shade and bundle sections of my POM: ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> <configuration> <filters> <filter> <artifact>cglib:cglib</artifact> <includes> <include>net/sf/cglib/core/**</include> <include>net/sf/cglib/proxy/**</include> </includes> </filter> </filters> <relocations> <relocation> <pattern>net.sf.cglib</pattern> <shadedPattern>org.modelmapper.internal.cglib</shadedPattern> </relocation> <relocation> <pattern>org.objectweb.asm</pattern> <shadedPattern>org.modelmapper.internal.asm</shadedPattern> </relocation> </relocations> </configuration> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.7</version> <executions> <execution> <id>bundle-manifest</id> <phase>process-classes</phase> <goals> <goal>manifest</goal> </goals> </execution> </executions> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Export-Package> org.modelmapper, org.modelmapper.builder, org.modelmapper.config, org.modelmapper.convention, org.modelmapper.spi </Export-Package> <Private-Package> org.modelmapper.internal.** </Private-Package> <Import-Package> * </Import-Package> <Include-Resource> {maven-resources}, {maven-dependencies} </Include-Resource> </instructions> </configuration> </plugin> ``` Taken from here