There is something close to what you want to achieve, but may be good enough.
However this will resolve all variables in POM sections of your choice.
I used resolveCiFriendliesOnly
, as it's the only mode that kind of preserves the original POM.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
<pomElements>
<dependencyManagement>resolve</dependencyManagement>
<!-- add more sections to resolve -->
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now you can add more sections under <pomElements>
where you want variables resolved.
As a side-effect of resolveCiFriendliesOnly
, variables ${revision}
, ${sha1}
and ${changelist}
will be resolved in the whole POM file.
Keep in mind that flatten-maven-plugin
will still rewrite your POM, i.e. you may get sections reordered, lose comments, indentation, etc.
Here's a list of sections you can configure:
https://www.mojohaus.org/flatten-maven-plugin/apidocs/org/codehaus/mojo/flatten/FlattenDescriptor.html
If resolveCiFriendliesOnly
still messes up your POM, you can remove flattenMode
, but then it will go wild and you must add nearly all possible sections to <pomElements>
with keep
option, e.g.
<pomElements>
<dependencyManagement>resolve</dependencyManagement>
<!-- keep everything else -->
<parent>keep</parent>
<build>keep</build>
<distributionManagement>keep</distributionManagement>
<repositories>keep</repositories>
<pluginRepositories>keep</pluginRepositories>
<profiles>keep</profiles>
...
</pomElements>