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

拜拜、爱过 提交于 2019-12-10 16:07:41

问题


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)


回答1:


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.




回答2:


I tried to skip goal deploy of maven-bundle-plugin 2.5.4 with this workaround:

<executions>
  <execution>
    <id>default-deploy</id>
    <phase>no-execute</phase>
    <goals>
      <goal>deploy</goal>
    </goals>
</execution>

This only worked for release numbers with qualifier in my case: e.g. 0.3.0-RC1. Release builds with release number without qualifier still did not work: e. g. 0.3.0.

Downgrading maven-bundle-plugin to 2.5.3 solved this issue, that the bundle was deployed twice. But I faced another issue: Maven Bundle Plugin fails with ArrayIndexOutOfBoundsException, "Invalid Class File"...

According to https://issues.apache.org/jira/browse/FELIX-4556, switching to bndlib version 2.4.0 works for me.

So I solved my issues by using maven-bundle-plugin 2.5.3 and using bndlib version 2.4.0:

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <version>2.5.3</version>
  <dependencies>
    <dependency>
      <groupId>biz.aQute.bnd</groupId>
      <artifactId>bndlib</artifactId>
      <version>2.4.0</version>
    </dependency>
  </dependencies>
<plugin>



回答3:


The version maven-bundle-plugin-2.5.5 works for me.



来源:https://stackoverflow.com/questions/31231453/when-using-bundle-packaging-with-maven-bundle-plugin-goals-are-executed-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!