0

我设法找到了解决问题的方法,但我想了解为什么我必须做我所做的事情,以及任何其他相关背景。

我正在开发一个生成 OSGi 包的 Maven 多项目构建,整个构建中有大约 48 个项目。

其中一些具有“src/main/resources/features.xml”文件,以及对“attach-artifact”目标的“build-helper-plugin”引用,以生成“features”工件。

每个“features.xml”文件都有一个“${pom.version}”字符串,因此生成的工件使用封闭 POM 文件的版本。

我发现其中一个模块正在生成仍然具有“${pom.version}”字符串的“features.xml”工件。没有发生属性过滤。这在任何其他模块中都没有发生。

这个错误的模块在其他方面也有所不同。所有其他模块都引用了“maven-bundle-plugin”并且是打包类型“bundle”。该模块是包装类型“pom”,不引用“maven-bundle-plugin”。

因此,我决定尝试将错误的 POM 更改为打包类型 bundle,并对“maven-bundle-plugin”进行“空”引用,而不覆盖默认值(我首先尝试仅更改打包类型,但失败了“没有这种包装类型”,有点可以理解)。

这行得通。错误模块现在生成一个带有“features.xml”文件的工件,其中属性引用替换为值。

我想了解为什么我必须这样做。

实际上我很惊讶我从来不必引用“maven-resources-plugin”,因为我认为我必须这样做才能获得任何属性过滤。看来这是默认完成的,可能是“build-helper-maven-plugin”的一部分。

更新

这是有问题的 POM,有一些省略:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>2.2.0-SNAPSHOT</version>
    <relativePath>...</relativePath>
  </parent>
  <artifactId>...</artifactId>
  <name>...</name>
  <url>http://maven.apache.org</url>
  <packaging>bundle</packaging> <!-- Change this to "pom" -->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
        <plugins>
            <plugin> <!-- Comment this plugin out -->
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>src/main/resources/features.xml</file>
                                    <type>xml</type>
                                    <classifier>features</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

请注意两条注释,一条关于“包装类型”,一条关于第一个插件定义。如果您在此处进行了描述的更改,它将不再对 features.xml 文件进行属性过滤。

这是来自 src/main/resources 的非常简单的“features.xml”文件,同样带有省略号:

<?xml version="1.0" encoding="UTF-8"?>
<features name="stuff-features" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">
<repository>mvn:.../...-servicefactory-impl/${pom.version}/xml/features</repository> 

   <feature name='stuff-all'>
   <feature>...-servicefactory</feature>
    </feature>
</features>

注意“${pom.version}”参考。POM 处于当前状态,生成的“features.xml”文件将替换为“2.2.0-SNAPSHOT”。如果您进行上述更改,它将不会进行过滤。

4

0 回答 0