5

I have a question regarding properties in a multi-module project.

Consider the following 3-level project struture:

project
+- pom.xml (packaging: pom)        //referred to as super-pom
+- module_group
   +- pom.xml (packaging: pom)     //referred to as group-pom
   +- module
      +-pom.xml (packaging: jar)   //referred to as module-pom

In the super-pom I define a property revision which gets the default value "unknown".

Additionally I declare and use the buildnumber-maven-plugin which is configured to get the svn revision and put it into property revision.

Next I configure the maven-jar-plugin to write that property into the manifest.

In th module-pom I declare usage of the buildnumber-maven-plugin so that is actually executed.


This all works when building the module directly, i.e. executing the module-pom only. The manifest contains the revision that is reported by the buildnumber-maven-plugin as is printed in the console.

However, if I execute the super-pom or group-pom the default value for revision is written to the manifest, although the buildnumber-maven-plugin gets executed and it retrieves the correct revision (it prints it to the console before the maven-jar-plugin runs).

So I have the feeling that I am missing something on property inheritance in multi-module projects.

Does anyone have an idea what could be wrong here? Or could anyone point me to a description of how properties are actually handled in those cases (unfortunately I didn't manage to find a good description yet)?

Update

I did some research and a few test runs with debug output (-X option) and from what I found so far, I assume my problem is the following:

1) During pom parsing the properties used in the pom are replaced with their values.

Consider this partial pom:

<!-- declare the property default value -->
<properties>
  <revision>default</revision>
</properties>

...

<!-- use the property -->
<someconfig>${revision}</someconfig>

After the pom is evaluated, it seems to result in a state that would correspond to this:

<properties>
  <revision>default</revision>
</properties>

...

<!-- The property seems to be "statically" replaced -->
<someconfig>default</someconfig>

2) The plugin that sets the actual property value runs afterwards, even if during the validate phase.

Thus the property itself is correctly set to the new value, but it is not read anymore.

3) The plugin that uses <someconfig> (in my case it would be the maven-jar-plugin) now runs with <someconfig>default</someconfig> and thus it doesn't read revision at all.

Can anyone confirm this?

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Thomas
  • 87,414
  • 12
  • 119
  • 157

1 Answers1

0

I can only say that declaring buildnumber-maven-plugin and maven-jar-plugin in a super-pom works well for me, no matter whether it is a group build or a targeted build.

Here's a part of this super-pom (a parent for all projects):

        <!-- Generate build number -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
            </configuration>
        </plugin>
        <!-- Attach build number to all jars -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Build>${buildNumber}</Implementation-Build>
                        <Implementation-Build-Timestamp>${maven.build.timestamp}</Implementation-Build-Timestamp>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
weekens
  • 8,064
  • 6
  • 45
  • 62