Search code examples
javamavenmaven-bundle-plugin

When using "bundle" packaging with maven-bundle-plugin goals are executed twice


I have a (simple) maven project with packaging type "bundle" using org.apache.felix:maven-bundle-plugin:2.5.4. It produces a correct OSGI bundle jar. However i observe that all goals are executed at least twice. How do i prevent this? Problem is that some goals (checkstyle in this example) are slow so duplicate execution is a problem here.

NOTE: I use maven 3.2.5 from the command line.

Output or mvn clean install (removed all irrelevant info). Notice that many plugins are executed 4 times. maven-checkstyle-plugin is execurted twice.

[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-project ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ my-project ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ my-project ---
[INFO] >>> maven-bundle-plugin:2.5.4:bundle (default-bundle) > package @ my-project >>>
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ my-project ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ my-project ---
[INFO] <<< maven-bundle-plugin:2.5.4:bundle (default-bundle) < package @ my-project <<<
[INFO] --- maven-bundle-plugin:2.5.4:bundle (default-bundle) @ my-project ---
[INFO] --- maven-checkstyle-plugin:2.15:check (checkstyle-main) @ my-project ---
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ my-project ---
[INFO] >>> maven-bundle-plugin:2.5.4:install (default-install) > install @ my-project >>>
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ my-project ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ my-project ---
[INFO] >>> maven-bundle-plugin:2.5.4:bundle (default-bundle) > package @ my-project >>>
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ my-project ---
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ my-project ---
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ my-project ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ my-project ---
[INFO] <<< maven-bundle-plugin:2.5.4:bundle (default-bundle) < package @ my-project <<<
[INFO] --- maven-bundle-plugin:2.5.4:bundle (default-bundle) @ my-project ---
[INFO] --- maven-checkstyle-plugin:2.15:check (checkstyle-main) @ my-project ---
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ my-project ---
[INFO] <<< maven-bundle-plugin:2.5.4:install (default-install) < install @ my-project <<<
[INFO] --- maven-bundle-plugin:2.5.4:install (default-install) @ my-project ---

Extra info:

Parent POM

<project ...>
    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>9</version>
    </parent>
    ...
    <version>3.0.5-SNAPSHOT</version>
    <packaging>pom</packaging>
    ...
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>2.5.4</version>
                    <extensions>true</extensions>
                    <inherited>true</inherited>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

POM for OSGI bundle:

<project ...>
    <parent>
        <groupId>myGroupId</groupId>
        <artifactId>myArtifactId</artifactId>
        <version>3.0.5-SNAPSHOT</version>
        <relativePath>../</relativePath>
    </parent>
    ...
    <packaging>bundle</packaging>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>myPackage</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

UPDATE: This is a known bug (also see answer K Erlandsson): https://issues.apache.org/jira/browse/FELIX-4882

This issue is resolved now (maven-bundle-plugin-2.5.5)


Solution

  • Edit: As rmuller have updated in the question, it is a bug: https://issues.apache.org/jira/browse/FELIX-4882. The bug is fixed in version 3.0.0.


    I recall us having a similar problem (specifically, the bundle was deployed twice) when we upgraded maven-bundle-plugin to 2.5.4. We downgraded it to 2.5.3 to solve our problems.

    I have not dug deeper to see if this is a bug or if there are just other requirements for configuration for 2.5.4.