为什么 OSGI 捆绑模块被构建两次

Why is OSGI bundle module getting built twice

我正在使用 Maven 构建这个多模块项目。项目根目录结构如下:

core (dir)
  |--- pom.xml
  |--- pom (dir)
        |---com.loc.dist.core.msp.osgi.pom (dir)
                 |---pom.xml
  |--- com.lgc.dist.core.msp.example.helloservice.client (dir)
                  |---pom.xml

项目 com.lgc.dist.core.msp.example.helloservice.client 被打包为 OSGI bundle 并且它是 com.loc.dist.core.msp.osgi.pom

的子模块
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.lgc.dist</groupId>
        <artifactId>com.lgc.dist.core.msp.osgi.pom</artifactId>
        <relativePath>../pom/com.lgc.dist.core.msp.osgi.pom</relativePath>
        <version>0.1</version>
    </parent>
    <artifactId>com.lgc.dist.core.msp.example.helloservice.client</artifactId>
    <packaging>bundle</packaging>

    <dependencies>
        <dependency>
            <groupId>com.lgc.dist</groupId>
            <artifactId>com.lgc.dist.core.msp.service</artifactId>
            <version>0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>com.lgc.dist.core.msp.example.helloservice.client.*;version=${project.version}</Export-Package>
                        <Private-Package>com.lgc.dist.core.msp.example.helloservice.client.internal</Private-Package>
                        <Import-Package>*</Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-scr-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

顶层的 pom.xml 显示 pom 文件夹,com.lgc.dist.core.msp.example.helloservice.client 在反应器列表中。

<modules>
        <module>pom</module>
        <module>com.lgc.dist.core.msp.example.helloservice.client</module>
    </modules>

当我从根部 运行 mvn clean install 时,它往往会背靠背构建 com.lgc.dist.core.msp.example.helloservice.client 两次。安装两次是可以的,但是我运行mvn deploy的时候就麻烦了。所有其他子模块只构建一次。只有 com.loc.dist.core.msp.osgi.pom 的子模块被构建了两次。我猜 osgi 默认构建所有的捆绑模块。但是,如果我在 pom.xml 中将其注释掉,则根本不会构建 osgi 包模块。我应该怎么做才能一次性构建这些 OSGI 包?

EDIT 如果我将打包模式从 bundle 更改为 jar,它工作正常,但这否定了拥有 OSGI 包的目的。

由于项目“com.lgc.dist.core.msp.example.helloservice.client”不是顶级 pom.xml 的直接子项目,请将其从那里删除。

因此,在顶层 pom.xml,条目应该是:

<modules>
    <module>pom/com.loc.dist.core.msp.osgi.pom</module>
</modules>

pom.xml 在 pom/com.loc.dist.core.msp.osgi.pom 中应该有:

<modules>
    <module>com.lgc.dist.core.msp.example.helloservice.client</module>
</modules>

经过一些研究,结果是 maven-bundle-plugin 2.5.4 默认部署了 bundle。根据 的答案之一,当使用带有 maven-bundle-plugin 目标的“bundle”打包时,执行两次 (我很惊讶它没有得到任何赞成票),你需要通过添加执行块来停止部署

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

现在正在运行。

EDIT,根据这个答案的评论,在2.5.5中解决。不过没试过。