This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 99a624d1f1 Forward-port #11985: remove redundant required MDO attrs +
add extension coordinate validation (#11979) (#12346)
99a624d1f1 is described below
commit 99a624d1f16a538361f6fe88fb55527726458412
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Jun 25 22:39:00 2026 +0200
Forward-port #11985: remove redundant required MDO attrs + add extension
coordinate validation (#11979) (#12346)
* Forward-port #11985: remove redundant required MDO attrs + add extension
coordinate validation (#11979)
- Remove <required>true</required> 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 WARNING-level validation for missing extension groupId/artifactId
- Add unit tests for extension coordinate validation and minimal POM
validation
* Address Copilot review comments (port from #12347)
- Fix <name> 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)
Note: unlike the 4.0.x branch, the test POM resources
minimal-with-parent.xml
and minimal-without-parent.xml are actually referenced by tests in
impl/maven-impl on master, so they are kept.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---------
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
api/maven-api-model/src/main/mdo/maven.mdo | 13 ---------
.../validation/DefaultModelValidatorTest.java | 12 ++++++++
.../validation/raw-model/minimal-with-parent.xml | 33 ++++++++++++++++++++++
.../raw-model/minimal-without-parent.xml | 29 +++++++++++++++++++
.../org/apache/maven/project/MavenProject.java | 1 -
.../maven/impl/model/DefaultModelValidator.java | 19 +++++++++++++
.../impl/model/DefaultModelValidatorTest.java | 22 +++++++++++++++
.../validation/missing-extension-coordinates.xml | 33 ++++++++++++++++++++++
.../validation/raw-model/minimal-with-parent.xml | 33 ++++++++++++++++++++++
.../raw-model/minimal-without-parent.xml | 29 +++++++++++++++++++
10 files changed, 210 insertions(+), 14 deletions(-)
diff --git a/api/maven-api-model/src/main/mdo/maven.mdo
b/api/maven-api-model/src/main/mdo/maven.mdo
index eb5618d9af..c5057ade7c 100644
--- a/api/maven-api-model/src/main/mdo/maven.mdo
+++ b/api/maven-api-model/src/main/mdo/maven.mdo
@@ -133,7 +133,6 @@
<field xdoc.separator="blank">
<name>groupId</name>
<version>3.0.0+</version>
- <required>true</required>
<description>
A universally unique identifier for a project. It is normal to
use a fully-qualified package name to distinguish it from other
@@ -154,7 +153,6 @@
<field>
<name>version</name>
<version>4.0.0+</version>
- <required>true</required>
<description>The current version of the artifact produced by this
project.</description>
<type>String</type>
</field>
@@ -181,7 +179,6 @@
<field xdoc.separator="blank">
<name>name</name>
<version>3.0.0+</version>
- <required>true</required>
<description>The full name of the project.</description>
<type>String</type>
</field>
@@ -247,7 +244,6 @@
<field>
<name>inceptionYear</name>
<version>3.0.0+</version>
- <required>true</required>
<description>The year of the project's inception, specified with 4
digits. This value is
used when generating copyright notices as well as being
informational.</description>
<type>String</type>
@@ -369,7 +365,6 @@
<field xdoc.separator="blank"
xml.insertParentFieldsUpTo="pluginRepositories">
<name>build</name>
<version>3.0.0+</version>
- <required>true</required>
<description>Information required to build the project.</description>
<association>
<type>Build</type>
@@ -906,7 +901,6 @@
<field>
<name>sourceDirectory</name>
<version>3.0.0+</version>
- <required>true</required>
<description>
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
@@ -923,7 +917,6 @@
<field>
<name>scriptSourceDirectory</name>
<version>4.0.0+</version>
- <required>true</required>
<description>
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
@@ -943,7 +936,6 @@
<field>
<name>testSourceDirectory</name>
<version>4.0.0+</version>
- <required>true</required>
<description>
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
@@ -2969,7 +2961,6 @@
<fields>
<field>
<name>id</name>
- <required>true</required>
<version>4.0.0+</version>
<type>String</type>
<defaultValue>default</defaultValue>
@@ -2989,7 +2980,6 @@
<field xml.tagName="build">
<name>build</name>
<version>4.0.0+</version>
- <required>true</required>
<description>Information required to build the project.</description>
<association>
<type>BuildBase</type>
@@ -3328,7 +3318,6 @@
<name>groupId</name>
<version>4.0.0+</version>
<type>String</type>
- <required>true</required>
<defaultValue>org.apache.maven.plugins</defaultValue>
<description>The group ID of the reporting plugin in the
repository.</description>
</field>
@@ -3422,7 +3411,6 @@
<field>
<name>id</name>
<type>String</type>
- <required>true</required>
<description>The unique id for this report set, to be used during
POM inheritance and profile injection
for merging of report sets.
</description>
@@ -3431,7 +3419,6 @@
<field>
<name>reports</name>
<version>4.0.0+</version>
- <required>true</required>
<description>The list of reports from this plugin which should be
generated from this set.</description>
<association>
<type>String</type>
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 08536d3d87..28fb582a3f 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
@@ -966,4 +966,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 0000000000..b373d50722
--- /dev/null
+++
b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml
@@ -0,0 +1,33 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.validation</groupId>
+ <artifactId>parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <artifactId>project</artifactId>
+
+</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 0000000000..274a34d2a0
--- /dev/null
+++
b/compat/maven-model-builder/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml
@@ -0,0 +1,29 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>groupId</groupId>
+ <artifactId>project</artifactId>
+ <version>project</version>
+
+</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 e6c2c05acb..e0f7d1c6e6 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/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
index 8cc8cb3459..c040fbbc75 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
@@ -55,6 +55,7 @@
import org.apache.maven.api.model.DependencyManagement;
import org.apache.maven.api.model.DistributionManagement;
import org.apache.maven.api.model.Exclusion;
+import org.apache.maven.api.model.Extension;
import org.apache.maven.api.model.InputLocation;
import org.apache.maven.api.model.InputLocationTracker;
import org.apache.maven.api.model.Model;
@@ -1068,6 +1069,24 @@ public void validateEffectiveModel(
validate20EffectivePluginDependencies(problems, plugin,
validationLevel);
}
+ for (Extension extension : build.getExtensions()) {
+ validateStringNotEmpty(
+ "build.extensions.extension.groupId",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ extension.getGroupId(),
+ extension);
+
+ validateStringNotEmpty(
+ "build.extensions.extension.artifactId",
+ problems,
+ Severity.WARNING,
+ Version.V20,
+ extension.getArtifactId(),
+ extension);
+ }
+
validate20RawResources(problems, build.getResources(),
"build.resources.resource.", validationLevel);
validate20RawResources(
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
index 591191e892..5b0cdd15ac 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
@@ -1022,4 +1022,26 @@ void profileActivationConditionWithBasedirExpression()
throws Exception {
"raw-model/profile-activation-condition-with-basedir.xml",
ModelValidator.VALIDATION_LEVEL_STRICT);
assertViolations(result, 0, 0, 0);
}
+
+ @Test
+ void testMissingExtensionCoordinates() throws Exception {
+ SimpleProblemCollector result =
validate("missing-extension-coordinates.xml");
+
+ assertViolations(result, 0, 0, 2);
+
+ assertContains(result.getWarnings().get(0),
"'build.extensions.extension.groupId' is missing.");
+ assertContains(result.getWarnings().get(1),
"'build.extensions.extension.artifactId' is missing.");
+ }
+
+ @Test
+ void minimalWithParent() throws Exception {
+ SimpleProblemCollector result =
validateRaw("raw-model/minimal-with-parent.xml");
+ assertViolations(result, 0, 0, 0);
+ }
+
+ @Test
+ void minimalWithoutParent() throws Exception {
+ SimpleProblemCollector result =
validateRaw("raw-model/minimal-without-parent.xml");
+ assertViolations(result, 0, 0, 0);
+ }
}
diff --git
a/impl/maven-impl/src/test/resources/poms/validation/missing-extension-coordinates.xml
b/impl/maven-impl/src/test/resources/poms/validation/missing-extension-coordinates.xml
new file mode 100644
index 0000000000..78c99289b2
--- /dev/null
+++
b/impl/maven-impl/src/test/resources/poms/validation/missing-extension-coordinates.xml
@@ -0,0 +1,33 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>foo</artifactId>
+ <groupId>foo</groupId>
+ <version>99.44</version>
+ <packaging>jar</packaging>
+ <build>
+ <extensions>
+ <extension>
+ <version>1.0</version>
+ </extension>
+ </extensions>
+ </build>
+</project>
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 0000000000..b373d50722
--- /dev/null
+++
b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-with-parent.xml
@@ -0,0 +1,33 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.validation</groupId>
+ <artifactId>parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <artifactId>project</artifactId>
+
+</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 0000000000..274a34d2a0
--- /dev/null
+++
b/impl/maven-impl/src/test/resources/poms/validation/raw-model/minimal-without-parent.xml
@@ -0,0 +1,29 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>groupId</groupId>
+ <artifactId>project</artifactId>
+ <version>project</version>
+
+</project>