Search code examples
mavenapache-felix

PluginVersionResolutionException in Maven project when I set packaging to bundle


In my Maven project when I change the packaging type from 'jar' to 'bundle' most of my plugins (compiler, deploy, install, resources, surefire) lose their versions. Why is this?

My pom.xml is below:

<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui_4.4.35_patch</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>4.2.1</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.artifactId}</Bundle-Name>
                    <Export-Package>web.admin.*</Export-Package>
                </instructions>
            </configuration>
        </plugin>

    </plugins>
</build>


Solution

  • There are two possible approaches. The one I use for my own projects is to keep the bundle packaging and add the maven plugin versions to a pluginManagement section in the pom.xml. For example:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    
        <!-- Add you current 'plugins' section here. -->
    </build>
    

    In addition to the version, you can also add configuration to each plugin. If your project has a parent pom, it would be natural to add the pluginManagement section there instead of in your bundle module.

    Alternatively, as suggested by @khmarbaise, you can use jar packaging and just use the maven-bundle-plugin to generate the manifest. That approach is described in the plugin documentation page.