Why modelVersion of pom.xml is necessary and always set to 4.0.0?

JavaMaven

Java Problem Overview


I have noticed that Maven's <modelVersion></modelVersion> of pom.xml is always set to 4.0.0.

Can you please help me understand what is the importance of this tag and why it should be set to 4.0.0?

Java Solutions


Solution 1 - Java

It is always set to 4.0.0 in Maven 2 and 3, because, at present, there is no other model.

> Notice that modelVersion contains 4.0.0. That is currently the only supported POM version, and is always required. [source]

But it wouldn't necessarily need to always be set to 4.0.0 if there was another version of the model. A POM has to comply with a model. Let's say Maven 4 comes up with model 4.1. If you write your pom to comply with 4.1, it wouldn't be compatible with Maven 3 and model 4.0.0.

It's defined as a mandatory, possibly to enforce a specific XML model in case new models are defined.

Solution 2 - Java

model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0.0 just indicated that it is compatible Maven 3.

Solution 3 - Java

The Correct answer should be the combination of the answers by @Toumi and @Boj. Also have a look at https://cwiki.apache.org/confluence/display/MAVEN/POM+Model+Version+5.0.0 for more background of this.

Solution 4 - Java

modelVersion - containing the model version of the POM. Maven 1.x used a model which contained a 3.0.0 element as an immediate child of the root. Maven 2.x / 3.x has used a 4.0.0 element.

version - containing the version of the project. If this attribute is missing then the parent element must be present and the version will be inherited from the parent project.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmaheshView Question on Stackoverflow
Solution 1 - JavaBojView Answer on Stackoverflow
Solution 2 - JavaToumiView Answer on Stackoverflow
Solution 3 - JavaAsankeView Answer on Stackoverflow
Solution 4 - JavaNilotpalView Answer on Stackoverflow