how to exclude GWT dependency code from OSGI bundle generated by MAven+BND?

I have several Maven modules with Vaadin library dependency in the root pom.xml file.

I'm trying to build a set of OSGI bundles (1 per Maven module) using Maven+BND.

I added this to my "root" pom.xml file:

    <dependencies>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin</artifactId>
        <version>6.6.6</version>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>1.0.0</version>
    </dependency>
    </dependencies>

unfortunately, the resulting JAR files (bundles) include GWT (com.google.gwt) classes. This 1) makes the bundles huge, with lots of duplicated dependencies. 2) generated thousands of build warnings about "split packages".

QUESTION: how to prevent adding GWT classes into my Jar files?

I tried setting "scope" of GWT to "provided", setting "type" to "bundle", and even optional=true - didn't help.

here's the part of my root pom.xml, which is responsible for Vaadin/GWT stuff:

    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.5</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Export-Package>mycompany.*</Export-Package>
                    <Private-Package>*.impl.*</Private-Package>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <!--                        <Bundle-Activator>com.alskor.publicpackage.MyActivator</Bundle-Activator>-->
                </instructions>
            </configuration>
        </plugin>
        <!-- Compiles your custom GWT components with the GWT compiler -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <!-- Version 2.1.0-1 works at least with Vaadin 6.5 -->
            <version>2.3.0-1</version>
            <configuration>
                <!-- if you don't specify any modules, the plugin will find them -->
                <!--modules>
                    ..
                </modules-->
                <webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets
                </webappDirectory>
                <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                <runTarget>clean</runTarget>
                <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                <noServer>true</noServer>
                <port>8080</port>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>resources</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Updates Vaadin 6.2+ widgetset definitions based on project dependencies -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
                <execution>
                    <configuration>
                        <!-- if you don't specify any modules, the plugin will find them -->
                        <!--
                        <modules>
                            <module>${package}.gwt.MyWidgetSet</module>
                        </modules>
                        -->
                    </configuration>
                    <goals>
                        <goal>update-widgetset</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

The wildcards in your Export-Package and Private-Package statements strike me as exceedingly dangerous. It's possible that the GWT packages are being dragged in because of the *.impl.* pattern in Private-Package.

Also you should never use wildcards in Export-Package: exports should be tightly controlled and versioned.


  • use mvn dependency:tree to see where the gwt dependency comes from
  • Add an <excludes/> element with an appropriate <exclude/> to the dependency in question to suppress it.
  • 链接地址: http://www.djcxy.com/p/74752.html

    上一篇: 基于Web的Web应用程序在Apache Felix中无法访问(404)

    下一篇: 如何从MAven + BND生成的OSGI包中排除GWT依赖代码?