Using getApplicationVersion()
as mentioned by khmarbaise has been deprecated, getMavenVersion()
is the recommended function to be used. You need to include maven-core 3.0.2 or higher as a dependency to use the RuntimeInformation
class.
here is the complete usage example,
Required pom dependency
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.2</version>
</dependency>
Package import
import org.apache.maven.rtinfo.RuntimeInformation;
Usage
/**
*
* @component
*/
private RuntimeInformation runtime;
public void execute() {
String version = runtime.getMavenVersion();
getLog().info("Maven Version: " + version);
...
}
@khmarbaise, Thanks for pointing me in the right direction