Maven - Version

1 - About

Version in Maven can refere to:

3 - Type

3.1 - Maven

To get the Maven Version, just execute this option


mvn --version

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200)
Maven home: C:\apache-maven-3.1.1\bin\..
Java version: 1.6.0_32, vendor: Sun Microsystems Inc.
Java home: C:\Progra~1\Java\jdk1.6.0_32\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

3.2 - Artifact

Version is one component of the artifact defined in the pom and follows the semantic versioning scheme.


<groupId>com.myWebSite</groupId>
<artifactId>myWebSite-nameArtifact</artifactId>
<version>1.5.3</version>

If version finishes with -SNAPSHOT, the release and deployment process follows the snapshot release process.

3.2.1 - How to pass the pom version to the code

To replace the artifact version in a class during the build process, you can use the below plugin:


<plugin>
	<groupId>com.google.code.maven-replacer-plugin</groupId>
	<artifactId>replacer</artifactId>
	<version>1.5.3</version>
	<executions>
		<execution>
			<phase>process-sources</phase>
			<goals>
				<goal>replace</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<ignoreMissingFile>false</ignoreMissingFile>
		<file>${project.build.sourceDirectory}/path/to/Version.java.template</file>
		<outputFile>${project.build.sourceDirectory}/path/to/Version.java</outputFile>
		<regex>false</regex>
		<token>@[email protected]</token>
		<value>${project.version}</value>
	</configuration>
</plugin>

where Version.java.template:


public class Version {
	private Version() {
		// don't instantiate
	}

	public static String id() {
		return "@[email protected]";
	}
	
	public static void main(String[] args) {
		System.out.println(id());
	}
}

4 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap