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 e60d230699 Maven model 4.1.0 should not allow non-pom packaging for
aggregators (#11279)
e60d230699 is described below
commit e60d23069979e7e9d3d0974508de41ac26d60933
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Oct 16 15:58:36 2025 +0200
Maven model 4.1.0 should not allow non-pom packaging for aggregators
(#11279)
The check is working when using `modules`, but has been forgotten when
introducing `subprojects`.
Fixes #11160
---
.../maven/impl/model/DefaultModelValidator.java | 26 ++++++++++++++++++-
.../impl/model/DefaultModelValidatorTest.java | 18 +++++++++++++
.../resources/poms/validation/empty-subproject.xml | 30 ++++++++++++++++++++++
...nvalid-aggregator-packaging-subprojects-pom.xml | 30 ++++++++++++++++++++++
4 files changed, 103 insertions(+), 1 deletion(-)
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 b97064f311..27b29148e9 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
@@ -910,7 +910,7 @@ public void validateEffectiveModel(
validateStringNotEmpty("packaging", problems, Severity.ERROR,
Version.BASE, model.getPackaging(), model);
- if (!model.getModules().isEmpty()) {
+ if (!model.getModules().isEmpty() ||
!model.getSubprojects().isEmpty()) {
if (!"pom".equals(model.getPackaging())) {
addViolation(
problems,
@@ -946,6 +946,30 @@ public void validateEffectiveModel(
model.getLocation("modules"));
}
}
+
+ for (int index = 0, size = model.getSubprojects().size(); index <
size; index++) {
+ String subproject = model.getSubprojects().get(index);
+
+ boolean isBlankSubproject = true;
+ if (subproject != null) {
+ for (int charIndex = 0; charIndex < subproject.length();
charIndex++) {
+ if
(!Character.isWhitespace(subproject.charAt(charIndex))) {
+ isBlankSubproject = false;
+ }
+ }
+ }
+
+ if (isBlankSubproject) {
+ addViolation(
+ problems,
+ Severity.ERROR,
+ Version.BASE,
+ "subprojects.subproject[" + index + "]",
+ null,
+ "has been specified without a path to the project
directory.",
+ model.getLocation("subprojects"));
+ }
+ }
}
validateStringNotEmpty("version", problems, Severity.ERROR,
Version.BASE, model.getVersion(), model);
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 6e8397d708..6ed6483340 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
@@ -543,6 +543,24 @@ void testEmptyModule() throws Exception {
assertTrue(result.getErrors().get(0).contains("'modules.module[0]' has
been specified without a path"));
}
+ @Test
+ void testInvalidAggregatorPackagingSubprojects() throws Exception {
+ SimpleProblemCollector result =
validate("invalid-aggregator-packaging-subprojects-pom.xml");
+
+ assertViolations(result, 0, 1, 0);
+
+ assertTrue(result.getErrors().get(0).contains("Aggregator projects
require 'pom' as packaging."));
+ }
+
+ @Test
+ void testEmptySubproject() throws Exception {
+ SimpleProblemCollector result = validate("empty-subproject.xml");
+
+ assertViolations(result, 0, 1, 0);
+
+
assertTrue(result.getErrors().get(0).contains("'subprojects.subproject[0]' has
been specified without a path"));
+ }
+
@Test
void testDuplicatePlugin() throws Exception {
SimpleProblemCollector result = validateFile("duplicate-plugin.xml");
diff --git
a/impl/maven-impl/src/test/resources/poms/validation/empty-subproject.xml
b/impl/maven-impl/src/test/resources/poms/validation/empty-subproject.xml
new file mode 100644
index 0000000000..03e039f3e8
--- /dev/null
+++ b/impl/maven-impl/src/test/resources/poms/validation/empty-subproject.xml
@@ -0,0 +1,30 @@
+<!--
+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.1.0</modelVersion>
+ <artifactId>aid</artifactId>
+ <groupId>gid</groupId>
+ <version>0.1</version>
+ <packaging>pom</packaging>
+
+ <subprojects>
+ <subproject> </subproject>
+ </subprojects>
+</project>
diff --git
a/impl/maven-impl/src/test/resources/poms/validation/invalid-aggregator-packaging-subprojects-pom.xml
b/impl/maven-impl/src/test/resources/poms/validation/invalid-aggregator-packaging-subprojects-pom.xml
new file mode 100644
index 0000000000..c4121ded84
--- /dev/null
+++
b/impl/maven-impl/src/test/resources/poms/validation/invalid-aggregator-packaging-subprojects-pom.xml
@@ -0,0 +1,30 @@
+<!--
+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.1.0</modelVersion>
+ <artifactId>foo</artifactId>
+ <groupId>foo</groupId>
+ <version>99.44</version>
+ <packaging>jar</packaging>
+
+ <subprojects>
+ <subproject>test-subproject</subproject>
+ </subprojects>
+</project>