Why does property filtering not happen on features.xml file unless packaging is bundle?

100 views Asked by At

I managed to find a solution to my problem, but I'd like to understand why I had to do what I did, any other relevant background.

I'm working on a Maven multi-project build that produces OSGi bundles, with about 48 projects in the entire build.

Some of them have a "src/main/resources/features.xml" file, along with a "build-helper-plugin" reference to the "attach-artifact" goal, to produce a "features" artifact.

Each one of the "features.xml" files has a "${pom.version}" string, so that the resulting artifact uses the version of the enclosing POM file.

I discovered that one of these modules is producing a "features.xml" artifact that still has the "${pom.version}" string. No property filtering occurred. This isn't happening in any of the other modules.

This errant module is also different in one other way. All the other modules have a reference to the "maven-bundle-plugin" and are packaging type "bundle". This module is packaging type "pom", and doesn't reference the "maven-bundle-plugin".

So I decided to try changing the errant POM to packaging type bundle and to have an "empty" reference to the "maven-bundle-plugin", with no overrides of defaults (I first tried just changing the packaging type, but that failed with "no such packaging type", somewhat understandable).

This worked. The errant module now produces an artifact with a "features.xml" file with the property reference replaced with the value.

I'd like to understand why I had to do this.

I was actually surprised that I never had to reference the "maven-resources-plugin", as I thought I would have to do that to get any property filtering. It appears this is done by default, perhaps as part of the "build-helper-maven-plugin".

Update:

This is the POM in question, with some elisions:

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

Note the two comments, one on the "packaging-type", and one on the first plugin definition. If you make the changes described there, it will no longer do property filtering on the features.xml file.

And here's the very simple "features.xml" file from src/main/resources, again with elisions:

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

Note the "${pom.version}" reference. With the POM in the current state, the generated "features.xml" file will have that replaced with "2.2.0-SNAPSHOT". If you make the changes described above, it will not do that filtering.

0

There are 0 answers