Ababababa
Ababababa

Reputation: 362

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!

Upvotes: 2

Views: 428

Answers (2)

Tran Phan
Tran Phan

Reputation: 1

PluginDescriptor is only available for Maven 3, if you don't wanna be restricted by Maven version, you could try addding this

@Parameter( defaultValue = "${mojoExecution}", readonly = true )
private MojoExecution mojo;

And get the version with

mojo.getPlugin().getVersion()

Upvotes: 0

Robert Scholte
Robert Scholte

Reputation: 12345

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

Upvotes: 3

Related Questions