15

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?

Lii
  • 11,553
  • 8
  • 64
  • 88
IcyBrk
  • 1,090
  • 12
  • 21
  • I wonder when I did not specify a plugin version in some module's pom.xml like in: Do you mean like this?? ` org.apache.maven.plugins maven-compiler-plugin ` – Vishwa Ratna Jan 02 '20 at 05:15
  • yes, that is what I mean. – IcyBrk Jan 04 '20 at 00:28
  • Does this answer your question? [How does Maven resolve plugin versions?](https://stackoverflow.com/questions/21128372/how-does-maven-resolve-plugin-versions) – Didier L Dec 22 '21 at 13:24

2 Answers2

8

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

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • Thank you, your answers exactly answered my question. From the reference you gave at the end of your post, I would gave two more related for clarification which is found from https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html. 1. https://maven.apache.org/ref/3.8.3/maven-core/lifecycles.html 2. https://maven.apache.org/ref/3.8.3/maven-core/default-bindings.html – IcyBrk Oct 16 '21 at 19:18
1

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.

Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55
  • The super POM, I also looked before, but that does not say what is the version of maven-compiler-plugin. Still thankful for the information provided. – IcyBrk Jan 02 '20 at 03:23
  • @IcyBrk , I am trying on my laptop and i feel that it is impossible to work without `version` , thedependency management is required and version must be specified either in `effective-pom` or `dependency tree.` , While in dependency management you can specify to use the latest version, but without Dependency management i feel it wont work. **correct me !** – Vishwa Ratna Jan 02 '20 at 03:31
  • have you tried to remove that dependency in the dependencyManagement and see what happend. – IcyBrk Jan 02 '20 at 03:40
  • I removed the version from `dependencyManagement ` and it does not work, in fact I am getting **ProjectBuildingException** – Vishwa Ratna Jan 02 '20 at 05:10
  • No, I mean remove the dependency element for maven-compiler-plugin in dependencyManagement. – IcyBrk Jan 04 '20 at 00:27