I have a maven based multi-module Java project. The root directory consists of various sub-modules as well as other directories which holds scripts, configurations and documentations files.
There are certain project metadata which will be provided by CI job via maven command and I want to replace the placeholders with these values.
For example, in CI job, I will pass parameters like below.
mvn clean install -Dpr.version=8.1.0-SNAPSHOT -Dstate.version=R12X -DLicense.key=CDW2025YY
my-project/ <-- Root directory (parent POM, not a real module)
│
├── pom.xml <-- Parent POM (packaging: pom)
├── scripts/
│ └── startup.ini <-- Needs token replacement
│
├── config/
│ └── helm-templates
│ └── some-config.template <-- Needs token replacement
│
├── module-A/ <-- Maven module
│ ├── pom.xml
│ └── src/
│ └── main/
│ └── resources/
│ └── application.properties <-- Needs token replacement
│
├── module-B/ <-- Another Maven module
├── pom.xml
└── ...
The other maven sub-modules are sorted and I am able to resolve placeholders as they are declared child of root pom.xml but since scripts and config directory in root directory are not declared child module in root pom.xml as they do not contain any source code, I am unable to resolve these placeholders in these directories.
I have tried maven-antrun-plugin to replace placeholders with their value. This is bind to validate phase. But on checking maven logs, I can see that the plugin is executing for all sub-modules but not for the parent pom.xml. The same I tried with maven-replacer-plugin as well but same results.
NOTE: If I run the antrun plugin explicitely via command "mvn antrun:run" then it works, but I want to bind this with "mvn clean install" command.
Below is my maven-antrun-plugin configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<inherited>false</inherited>
<executions>
<execution>
<id>replace-pr-version</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>Replacing version string in files at root level</echo>
<replace token="##PR_VERSION##" value="${pr.version}">
<fileset dir="${project.basedir}">
<include name="config/helm-templates/some-config.template"/>
<include name="scripts/startup.ini"/>
</fileset>
</replace>
</target>
</configuration>
</execution>
</executions>
</plugin>
scripts,config... theapplication.propertiescan be configured to be filtered within the module...