From fe1a944d140a919433c1031d29e23f8fc8f29aac Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 23 Jun 2026 07:26:49 +0000 Subject: [PATCH 1/2] Forward-port #11985: remove redundant required MDO attrs (#11979) Remove true from 13 metadata/defaulted fields in maven.mdo (forward-port of PR #11985 from maven-3.10.x). Update Model.name description to document artifactId fallback. Add minimal POM validation tests. --- api/maven-api-model/src/main/mdo/maven.mdo | 15 +-------- .../validation/DefaultModelValidatorTest.java | 12 +++++++ .../raw-model/minimal-with-parent.xml | 33 +++++++++++++++++++ .../raw-model/minimal-without-parent.xml | 29 ++++++++++++++++ .../apache/maven/project/MavenProject.java | 1 - .../raw-model/minimal-with-parent.xml | 33 +++++++++++++++++++ .../raw-model/minimal-without-parent.xml | 29 ++++++++++++++++ 7 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml create mode 100644 compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml create mode 100644 impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml create mode 100644 impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml diff --git a/api/maven-api-model/src/main/mdo/maven.mdo b/api/maven-api-model/src/main/mdo/maven.mdo index 83dc5aff1daf..ac0f5fe89b95 100644 --- a/api/maven-api-model/src/main/mdo/maven.mdo +++ b/api/maven-api-model/src/main/mdo/maven.mdo @@ -119,7 +119,6 @@ groupId 3.0.0+ - true A universally unique identifier for a project. It is normal to use a fully-qualified package name to distinguish it from other @@ -140,7 +139,6 @@ version 4.0.0+ - true The current version of the artifact produced by this project. String @@ -167,8 +165,7 @@ name 3.0.0+ - true - The full name of the project. + The full name of the project. If not specified, the artifactId will be used. String @@ -233,7 +230,6 @@ inceptionYear 3.0.0+ - true The year of the project's inception, specified with 4 digits. This value is used when generating copyright notices as well as being informational. String @@ -355,7 +351,6 @@ build 3.0.0+ - true Information required to build the project. Build @@ -887,7 +882,6 @@ sourceDirectory 3.0.0+ - true This element specifies a directory containing the source of the project. The generated build system will compile the sources from this directory when the project is @@ -904,7 +898,6 @@ scriptSourceDirectory 4.0.0+ - true This element specifies a directory containing the script sources of the project. This directory is meant to be different from the sourceDirectory, in that its @@ -922,7 +915,6 @@ testSourceDirectory 4.0.0+ - true This element specifies a directory containing the unit test source of the project. The generated build system will compile these directories when the project is @@ -2931,7 +2923,6 @@ id - true 4.0.0+ String default @@ -2951,7 +2942,6 @@ build 4.0.0+ - true Information required to build the project. BuildBase @@ -3290,7 +3280,6 @@ groupId 4.0.0+ String - true org.apache.maven.plugins The group ID of the reporting plugin in the repository. @@ -3384,7 +3373,6 @@ id String - true The unique id for this report set, to be used during POM inheritance and profile injection for merging of report sets. @@ -3393,7 +3381,6 @@ reports 4.0.0+ - true The list of reports from this plugin which should be generated from this set. String diff --git a/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 4d6c3faf1b73..cfa3b44a7044 100644 --- a/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -958,4 +958,16 @@ void testConcurrentValidation() throws Exception { "Concurrent validation failed: " + failure.get().getMessage(), failure.get()); } } + + @Test + void testMinimalWithParent() throws Exception { + SimpleProblemCollector result = validateRaw("raw-model/minimal-with-parent.xml"); + assertViolations(result, 0, 0, 0); + } + + @Test + void testMinimalWithoutParent() throws Exception { + SimpleProblemCollector result = validateRaw("raw-model/minimal-without-parent.xml"); + assertViolations(result, 0, 0, 0); + } } diff --git a/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml new file mode 100644 index 000000000000..b373d50722d9 --- /dev/null +++ b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + + org.apache.maven.validation + parent + 1 + + + project + + diff --git a/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml new file mode 100644 index 000000000000..274a34d2a087 --- /dev/null +++ b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml @@ -0,0 +1,29 @@ + + + + 4.0.0 + + groupId + project + project + + diff --git a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index e6c2c05acbf0..e0f7d1c6e65c 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -632,7 +632,6 @@ public void setName(String name) { } public String getName() { - // TODO this should not be allowed to be null. if (getModel().getName() != null) { return getModel().getName(); } else { diff --git a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml new file mode 100644 index 000000000000..b373d50722d9 --- /dev/null +++ b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + + org.apache.maven.validation + parent + 1 + + + project + + diff --git a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml new file mode 100644 index 000000000000..274a34d2a087 --- /dev/null +++ b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml @@ -0,0 +1,29 @@ + + + + 4.0.0 + + groupId + project + project + + From fca2bce6f05a0fe9e2142747a1489dadab3ed7fd Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 25 Jun 2026 04:19:19 +0000 Subject: [PATCH 2/2] Address Copilot review comments - Fix field description in maven.mdo to not claim the model field defaults to artifactId (the fallback is a runtime behavior in MavenProject#getName(), not a model-level default) - Remove unused test POM resources minimal-with-parent.xml and minimal-without-parent.xml from impl/maven-impl (only referenced in compat/maven-model-builder tests which have their own copies) Co-Authored-By: Claude Opus 4.6 --- api/maven-api-model/src/main/mdo/maven.mdo | 2 +- .../raw-model/minimal-with-parent.xml | 33 ------------------- .../raw-model/minimal-without-parent.xml | 29 ---------------- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml delete mode 100644 impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml diff --git a/api/maven-api-model/src/main/mdo/maven.mdo b/api/maven-api-model/src/main/mdo/maven.mdo index ac0f5fe89b95..69431f1d92e5 100644 --- a/api/maven-api-model/src/main/mdo/maven.mdo +++ b/api/maven-api-model/src/main/mdo/maven.mdo @@ -165,7 +165,7 @@ name 3.0.0+ - The full name of the project. If not specified, the artifactId will be used. + The full name of the project. String diff --git a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml deleted file mode 100644 index b373d50722d9..000000000000 --- a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - 4.0.0 - - - org.apache.maven.validation - parent - 1 - - - project - - diff --git a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml deleted file mode 100644 index 274a34d2a087..000000000000 --- a/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - 4.0.0 - - groupId - project - project - -