Search code examples
javaosgibndmaven-bundle-plugin

How to exclude a named package from a dependency that exists in another dependency using Maven Bundle Plugin (BND)?


I have two dependencies:

<dependency>
    <groupId>org.postgis</groupId>
    <artifactId>postgis-jdbc</artifactId>
    <version>1.5.2</version>
</dependency>
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>com.springsource.org.postgresql.jdbc4</artifactId>
    <version>8.3.604</version>
</dependency>

Both dependencies export package:

  • org.postgres

How can I exclude exporting org.postgres from postgis-jdbc when using the Maven Bundle Plugin's wrap command?


Solution

  • Using the Maven Bundle Plugin, I couldn't find a practical way of selectively excluding package exports for selected wrapped dependencies. My solution was to instead embed both com.springsource.org.postgresql.jdbc4 and postgis-jdbc in my bundle, and not export their packages:

    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.7</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
                ...
                <Embed-Dependency>
                    postgresql;postgis-jdbc
                </Embed-Dependency>
                ...
            </instructions>
        </configuration>
        <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>bundle</goal>
               </goals>
            </execution>
        </executions>
    </plugin>