当使用带有maven-bundle-plugin的“bundle”打包时,目标会被执行两次

时间:2015-07-05 14:36:36

标签: java maven maven-bundle-plugin

我有一个(简单的)maven项目,使用org.apache.felix:maven-bundle-plugin:2.5.4打包类型为“bundle”。它产生一个正确的OSGI束罐。但是我观察到所有目标至少执行两次。我该如何防止这种情况?问题是某些目标(本例中的checkstyle)很慢,因此重复执行是一个问题。

注意:我从命令行使用maven 3.2.5。

输出或mvn clean install(删除所有不相关的信息)。请注意,许多插件执行4次。 maven-checkstyle-plugin被执行两次。

[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 ---

额外信息:

父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>

OSGI包的POM:

<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>

更新:这是一个已知错误(另请参阅答案K Erlandsson):https://issues.apache.org/jira/browse/FELIX-4882

此问题现已解决(maven-bundle-plugin-2.5.5

3 个答案:

答案 0 :(得分:6)

修改:由于 rmuller 已在问题中更新,因此它是一个错误:https://issues.apache.org/jira/browse/FELIX-4882。该错误已在版本expect(scope.status).toBe(200)中修复。

当我们将3.0.0升级为maven-bundle-plugin时,我记得我们遇到了类似的问题(具体来说,捆绑包已部署了两次)。我们将其降级为2.5.4以解决我们的问题。

我没有深入研究这是否是一个错误,或者2.5.3是否只有其他配置要求。

答案 1 :(得分:1)

我尝试使用此解决方法跳过maven-bundle-plugin 2.5.4的目标部署:

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

这仅适用于我的情况下带限定符的版本号:例如0.3.0-RC1。 使用版本号发布版本而没有限定符仍然无效:e。 G。 0.3.0

将maven-bundle-plugin降级到2.5.3解决了这个问题,该捆绑包已经部署了两次。但我面临另一个问题: Maven Bundle Plugin fails with ArrayIndexOutOfBoundsException, "Invalid Class File" ...

根据https://issues.apache.org/jira/browse/FELIX-4556,切换为bndlib版本2.4.0对我有用。

所以我使用maven-bundle-plugin 2.5.3并使用bndlib版本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>

答案 2 :(得分:-1)

shouldComponentUpdate版本适合我。