I am writing a plugin to Maven. I want to customize action depend on Maven version (person’s who use my plugin)
something like:
if (MavenVer == "2.2.1")
//do some things
if (MavenVer == "3.0")
//do another things
I found out build-helper-maven-plugin but i’m not shure how to use it to do this job.
I have been looking for an answer to your question and I have come to the conclusion that there is no simple way to get the maven version, or at least I couldn’t find it. The best I was able to find is that the maven-enforcer-plugin contains code that looks up the maven version. However in looking at the maven-enforcer-plugin source code it is a little complicated and involves getting a handle to a RuntimeInformation instance through plexus (the IoC container used by Maven).
I recommend you take a look at the maven-enforcer-plugin and see if you can use what they did. Pay particular attention to RequireMavenVersion and EnforcerMojo classes.