How do I get the Maven version of my project programatically?
In other words:
static public String getVersion()
{
...what goes here?...
}
For example, if my project would generate the jar CalculatorApp-1.2.3.jar
, I want getVersion()
to return 1.2.3
.
Before moving on, we can check the default JDK version of Maven. Running the mvn -v command will show the Java version in which Maven runs.
Use the properties-maven-plugin to write specific pom properties to a file at compile time, and then read that file at run time.
version. It is the sub element of project. It specifies the version of the artifact under given group. File: pom.xml.
For jar files, you have the MANIFEST.MF as the default place to put the Implementation-Version there. Maven supports building the jar file like this.
See also How do I add an Implementation-Version value to a jar manifest using Maven?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With