About maven plugin version tag

397 Views Asked by At

We all know, when we use plugin or dependency in maven pom.xml, we must give the GAV(groupId, artifactId, version).That maven can know what plugin or dependency you want.
eg:

<!-- generate source plugin -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
    <!-- ...others config -->
</plugin>

but, if i write like that:
eg:

<!-- generate source plugin -->
<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <!-- ...others config -->
</plugin>

that is right!why?Maven says we must give GAV?Why that is right when i only give A?

So I want know if I don't give G and V,that maven will use what G or V?

1

There are 1 best solutions below

2
On BEST ANSWER

The reason you don't have to specify the version is because it gets inherited from the Maven super POM (http://maven.apache.org/guides/introduction/introduction-to-the-pom.html). This super POM has a definition for the maven-source-plugin that specifies the version to be used.

If you declare other dependencies or plugins that are not declared in the super POM, then the version is required. Note however, that it is a good practise to explicitly declare the versions of the plugins you want to use in your own pom.xml to make your build more reproducible.

You can leave out the group id in this case, because maven will seach for org.apache.maven.plugins as groupId if no groupId was specified. So this will only work for the official Maven plugins that use this group id.