Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is default Maven plugin version decided?

Tags:

java

maven

I wonder when I did not specify a plugin version in some module's pom.xml like in:

<build>
...
<plugin>
   <groudId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.8.0</version>
</plugin>
...
</build>

What is the default plugin version used when I run "mvn compile"?

I have tried it and see actually it is using maven-compiler-plugin version 3.1 with above plugin element commented, my Maven version is 3.6.3.

I have spent 1 hour to google through Maven's documentation and related posts, but not find exact answer. I really like to know how that version is being decided?

like image 585
IcyBrk Avatar asked Jan 02 '20 03:01

IcyBrk


People also ask

What is the latest version of Maven compiler plugin?

Apache Maven Compiler Plugin 3.10. This is the current stable version of Apache Maven Compiler Plugin.

What is Maven plugin version?

Maven Plugin Plugin/ | Last Published: 2022-01-11. Version: 3.6.4.


Video Answer


2 Answers

The magic is not happening in the super pom, but in the so called bindings descriptor as available at https://github.com/apache/maven/blob/master/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml. However, they are moving to the matching packaging plugin, for example for the maven-jar-plugin it is located at https://github.com/apache/maven-jar-plugin/blob/master/src/main/filtered-resources/META-INF/plexus/components.xml These versions haven't been updated, because it would be weird if 2 users with different Maven versions have different results (e.g. one has a broken build, the other not). Hence it is better to specify the plugin versions in the pom, don't rely of the defaults provided by Maven.

In the end it is all described at https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

like image 179
Robert Scholte Avatar answered Oct 19 '22 17:10

Robert Scholte


It is impossible for maven to work without defining versions of the artifacts , so somewhere it must be mentioned, lets dig in part by part.

All pom.xmls are logically inherit from the super POM. You can always see what your "real" pom.xml looks like by typing:

mvn help:effective-pom

The resulting pom.xml that is printed is a combination of the super POM, your pom.xml, and any parent POMs in the mix as well.

Note from Maven 3 the super POM does not contain any of the (default lifecycle) plugins versions but earlier till Maven 2 it used to have.

The Maven 3 super POM is provided by the org.apache.maven.model.superpom.DefaultSuperPomProvider class https://github.com/apache/maven/blob/bce33aa2662a51d18cb00347cf2fb174dc195fb1/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java#L56-L85

The resource it loads can be found here: https://github.com/apache/maven/blob/bce33aa2662a51d18cb00347cf2fb174dc195fb1/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml#L23-L149


Edit:

As per Maven Coordinates

groupId:artifactId:version are all required fields (although, groupId and version need not be explicitly defined if they are inherited from a parent - more on inheritance later). The three fields act much like an address and timestamp in one. This marks a specific place in a repository, acting like a coordinate system for Maven projects:

version: This is the last piece of the naming puzzle. groupId:artifactId denotes a single project but they cannot delineate which incarnation of that project we are talking about. Do we want the junit:junit of 2018 (version 4.12), or of 2007 (version 3.8.2)? In short: code changes, those changes should be versioned, and this element keeps those versions in line. It is also used within an artifact's repository to separate versions from each other. my-project version 1.0 files live in the directory structure $M2_REPO/org/codehaus/mojo/my-project/1.0.

like image 25
Vishwa Ratna Avatar answered Oct 19 '22 18:10

Vishwa Ratna