Search code examples
javamavenpluginsruntimemaven-plugin

How to get current maven goal version


In a maven plugin project if you use

@Parameter(defaultValue = "${project}")
private MavenProject project;

Then you get the project that runs this plugin. How to get version of current Maven goal inside the maven goal itself, more specifically, this part of the project's pom.xml?

<plugins>
      <plugin>
        <groupId>com.my.maven.plugins</groupId>
        <artifactId>my-maven-plugin</artifactId>
        <version>!! I want to get this !!</version>
      </plugin>
<plugins>

Thanks!


Solution

  • Add this to your mojo:

    @Parameter( defaultValue = "${plugin}", readonly = true ) // Maven 3 only
    private PluginDescriptor plugin;
    

    Other available instances can be found at https://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html#Supported_Annotations