Issue
I have a project that consists of multiple Maven sub projects. And the structure looks like this
my-project
|
|__sub-project-1
|__sub-project-2
|__sub-project-3
|__sub-project-4
|__sub-project-5
|__sub-project-6
|__sub-project-7
|__scripts
|__pom.xml
Inside the folder scripts I have shell scripts that start my sub projects, i.e.
java \
-jar -Djava.net.preferIPv4Stack=true \
-Ddata.folder="test-data" \
<...>
"sub-project-1.[1.0.1].jar" \
<...>
I want to make so, that version (inside square brackets) in shell scripts would update after changing the version inside a sub-project[n] pom.xml.
What is a standard way to achieve?
Solution
From "Maven project version inheritance - do I have to specify the parent version?", the modules of a multi-project are supposed to inherit the parent version.
That allows all children projects to be updated through one mvn
command.
That means there should be only one version to manage.
But if not, you would need your script to extract the version through:
-
VERSION=$(mvn exec:exec -Dexec.executable='echo' \ -Dexec.args='${project.version}' --non-recursive -q)
or through bash (even on Windows, using Git for Windows)
cat pom.xml | grep "^ <version>.*</version>$" | awk -F'[><]' '{print $3}'
Answered By - VonC
Answer Checked By - Mary Flores (JavaFixing Volunteer)