Maven parent version ${revision} expansion in cross project inheritance

1.1k views Asked by At

Background:
I'm using maven 3.5 and have a 'master' aggregator project which has 4 modules (uses both aggregation and inheritance).
I also have 30 separate child projects, both single and multi-module, which each inherit from one of those 4 modules.

Problem:

I'd like to use ${revision} in the <parent><version> tag of the child projects but what I observe is maven trying to resolve the parent before expanding ${revision} (to the value specified in <properties><revision>). This results in maven being unable to resolve the parent since it's looking for the literal "${revision}" version of the parent project.

Questions

  • Is it true that ${revision} does not work for cross project inheritance ?

  • is there any work around ? (while trying to avoid maven-versions plugin)

Note: I'm able to use ${revision} without any problems in a single multi-module project - that's not the issue.

2

There are 2 answers

0
Jonas Bergström On

I just ran into the same issue, but it works for me with maven 3.8.2.

0
Alao On

I ran across this issue and had to use a flatten plugin in my parent pom. First, you add the revision in the properties

<properties>
    <revision>2.1.0-SNAPSHOT</revision>
    <mssql-jdbc.version>9.4.1.jre11</mssql-jdbc.version>
    <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
    <flatten-maven-plugin.version>1.1.0</flatten-maven-plugin.version>
</properties>

Then add this plugin to the build section

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>flatten-maven-plugin</artifactId>
            <version>${flatten-maven-plugin.version}</version>
            <configuration>
                <updatePomFile>true</updatePomFile>
                <flattenMode>resolveCiFriendliesOnly</flattenMode>
            </configuration>
            <executions>
                <execution>
                    <id>flatten</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>flatten</goal>
                    </goals>
                </execution>
                <execution>
                    <id>flatten.clean</id>
                    <phase>clean</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>