You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/21 11:23:29 UTC
(maven) branch maven-3.10.x updated: Maven 3.10.x should use Maven 3.1 validation in strict mode
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-3.10.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.10.x by this push:
new af936f4e9b Maven 3.10.x should use Maven 3.1 validation in strict mode
af936f4e9b is described below
commit af936f4e9bfbfaf11d17b8448ddcd59f22ca5161
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Sep 21 13:23:22 2026 +0200
Maven 3.10.x should use Maven 3.1 validation in strict mode
- Set VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_1 so that
3.1-level checks (duplicate plugins, bad version chars, bad snapshot
format, reserved/bad repository IDs) are reported as errors in strict
mode, matching the maturity of the 3.1 checks since Maven 3.1 (2012)
- Add tests for the new strict-mode behaviour (*30 variants vs default)
- Fix fragile activeByDefault profile in test fixture: use explicit
profile activation via setActiveProfileIds to avoid CI environments
deactivating the profile when other profiles are active
---
.../project/DefaultMavenProjectBuilderTest.java | 5 +-
.../projects/duplicate-plugins-merged-pom.xml | 54 +++++++-----
.../maven/model/building/ModelBuildingRequest.java | 2 +-
.../validation/DefaultModelValidatorTest.java | 99 ++++++++++++++++++----
4 files changed, 122 insertions(+), 38 deletions(-)
diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index e3a7bd159e..feee05f3a5 100644
--- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -19,6 +19,7 @@
package org.apache.maven.project;
import java.io.File;
+import java.util.Arrays;
import java.util.List;
import org.apache.maven.artifact.Artifact;
@@ -79,7 +80,9 @@ public void testBuildFromMiddlePom() throws Exception {
public void testDuplicatePluginDefinitionsMerged() throws Exception {
File f1 = getTestFile("src/test/resources/projects/duplicate-plugins-merged-pom.xml");
- MavenProject project = getProject(f1);
+ ProjectBuildingRequest configuration = newBuildingRequest();
+ configuration.setActiveProfileIds(Arrays.asList("foo"));
+ MavenProject project = projectBuilder.build(f1, configuration).getProject();
assertEquals(2, project.getBuildPlugins().get(0).getDependencies().size());
assertEquals(2, project.getBuildPlugins().get(0).getExecutions().size());
assertEquals(
diff --git a/maven-core/src/test/resources/projects/duplicate-plugins-merged-pom.xml b/maven-core/src/test/resources/projects/duplicate-plugins-merged-pom.xml
index 7383109f0e..5f0051fbc9 100644
--- a/maven-core/src/test/resources/projects/duplicate-plugins-merged-pom.xml
+++ b/maven-core/src/test/resources/projects/duplicate-plugins-merged-pom.xml
@@ -1,5 +1,5 @@
-<project>
- <modelVersion>4.0.0</modelVersion>
+<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>tests.project</groupId>
<artifactId>duplicate-plugin-defs-merged</artifactId>
<version>1</version>
@@ -8,6 +8,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>3.11.0</version>
<dependencies>
<dependency>
<groupId>group</groupId>
@@ -24,25 +25,36 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>group</groupId>
- <artifactId>second</artifactId>
- <version>1</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>second</id>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
+ </plugins>
</build>
+ <profiles>
+ <profile>
+ <id>foo</id>
+ <activation><property><name>activateFooProfile</name></property></activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>group</groupId>
+ <artifactId>second</artifactId>
+ <version>1</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>second</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
index 98649e0b44..1465a30580 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
@@ -60,7 +60,7 @@ public interface ModelBuildingRequest {
/**
* Denotes strict validation as recommended by the current Maven version.
*/
- int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
+ int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_1;
/**
* Gets the raw model to build. If not set, model source will be used to load raw model.
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
index b2912a17dd..a72946ed5e 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
@@ -54,6 +54,10 @@ private SimpleProblemCollector validate(String pom) throws Exception {
return validateEffective(pom, UnaryOperator.identity());
}
+ private SimpleProblemCollector validate(String pom, int level) throws Exception {
+ return validateEffective(pom, mbr -> mbr.setValidationLevel(level));
+ }
+
private SimpleProblemCollector validateRaw(String pom) throws Exception {
return validateRaw(pom, UnaryOperator.identity());
}
@@ -428,7 +432,8 @@ public void testIncompleteParent() throws Exception {
@Test
public void testHardCodedSystemPath() throws Exception {
- SimpleProblemCollector result = validateRaw("hard-coded-system-path.xml");
+ SimpleProblemCollector result =
+ validateRaw("hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
assertViolations(result, 0, 0, 1);
@@ -436,8 +441,7 @@ public void testHardCodedSystemPath() throws Exception {
result.getWarnings().get(0),
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path");
- SimpleProblemCollector result31 =
- validateRaw("hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1);
+ SimpleProblemCollector result31 = validateRaw("hard-coded-system-path.xml");
assertViolations(result31, 0, 0, 3);
@@ -462,8 +466,9 @@ public void testEmptyModule() throws Exception {
}
@Test
- public void testDuplicatePlugin() throws Exception {
- SimpleProblemCollector result = validateRaw("duplicate-plugin.xml");
+ public void testDuplicatePlugin30() throws Exception {
+ SimpleProblemCollector result =
+ validateRaw("duplicate-plugin.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
assertViolations(result, 0, 0, 4);
@@ -473,6 +478,18 @@ public void testDuplicatePlugin() throws Exception {
assertTrue(result.getWarnings().get(3).contains("duplicate declaration of plugin profile:managed-duplicate"));
}
+ @Test
+ public void testDuplicatePlugin() throws Exception {
+ SimpleProblemCollector result = validateRaw("duplicate-plugin.xml");
+
+ assertViolations(result, 0, 4, 0);
+
+ assertTrue(result.getErrors().get(0).contains("duplicate declaration of plugin test:duplicate"));
+ assertTrue(result.getErrors().get(1).contains("duplicate declaration of plugin test:managed-duplicate"));
+ assertTrue(result.getErrors().get(2).contains("duplicate declaration of plugin profile:duplicate"));
+ assertTrue(result.getErrors().get(3).contains("duplicate declaration of plugin profile:managed-duplicate"));
+ }
+
@Test
public void testDuplicatePluginExecution() throws Exception {
SimpleProblemCollector result = validateRaw("duplicate-plugin-execution.xml");
@@ -486,8 +503,9 @@ public void testDuplicatePluginExecution() throws Exception {
}
@Test
- public void testReservedRepositoryId() throws Exception {
- SimpleProblemCollector result = validate("reserved-repository-id.xml");
+ public void testReservedRepositoryId30() throws Exception {
+ SimpleProblemCollector result =
+ validate("reserved-repository-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
assertViolations(result, 0, 0, 4);
@@ -498,6 +516,18 @@ public void testReservedRepositoryId() throws Exception {
result.getWarnings().get(3), "'distributionManagement.snapshotRepository.id' must not be 'local'");
}
+ @Test
+ public void testReservedRepositoryId() throws Exception {
+ SimpleProblemCollector result = validate("reserved-repository-id.xml");
+
+ assertViolations(result, 0, 4, 0);
+
+ assertContains(result.getErrors().get(0), "'repositories.repository.id'" + " must not be 'local'");
+ assertContains(result.getErrors().get(1), "'pluginRepositories.pluginRepository.id' must not be 'local'");
+ assertContains(result.getErrors().get(2), "'distributionManagement.repository.id' must not be 'local'");
+ assertContains(result.getErrors().get(3), "'distributionManagement.snapshotRepository.id' must not be 'local'");
+ }
+
@Test
public void testMissingPluginDependencyGroupId() throws Exception {
SimpleProblemCollector result = validate("missing-plugin-dependency-groupId.xml");
@@ -534,27 +564,47 @@ public void testBadPluginDependencyVersion() throws Exception {
assertTrue(result.getErrors().get(0).contains("test:b"));
}
+ @Test
+ public void testBadVersion30() throws Exception {
+ SimpleProblemCollector result = validate("bad-version.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
+ assertViolations(result, 0, 0, 1);
+
+ assertContains(result.getWarnings().get(0), "'version' must not contain any of these characters");
+ }
+
@Test
public void testBadVersion() throws Exception {
SimpleProblemCollector result = validate("bad-version.xml");
+ assertViolations(result, 0, 1, 0);
+
+ assertContains(result.getErrors().get(0), "'version' must not contain any of these characters");
+ }
+
+ @Test
+ public void testBadSnapshotVersion30() throws Exception {
+ SimpleProblemCollector result =
+ validate("bad-snapshot-version.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
+
assertViolations(result, 0, 0, 1);
- assertContains(result.getWarnings().get(0), "'version' must not contain any of these characters");
+ assertContains(result.getWarnings().get(0), "'version' uses an unsupported snapshot version format");
}
@Test
public void testBadSnapshotVersion() throws Exception {
SimpleProblemCollector result = validate("bad-snapshot-version.xml");
- assertViolations(result, 0, 0, 1);
+ assertViolations(result, 0, 1, 0);
- assertContains(result.getWarnings().get(0), "'version' uses an unsupported snapshot version format");
+ assertContains(result.getErrors().get(0), "'version' uses an unsupported snapshot version format");
}
@Test
- public void testBadRepositoryId() throws Exception {
- SimpleProblemCollector result = validate("bad-repository-id.xml");
+ public void testBadRepositoryId30() throws Exception {
+ SimpleProblemCollector result =
+ validate("bad-repository-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
assertViolations(result, 0, 0, 4);
@@ -571,6 +621,25 @@ public void testBadRepositoryId() throws Exception {
"'distributionManagement.snapshotRepository.id' must not contain any of these characters");
}
+ @Test
+ public void testBadRepositoryId() throws Exception {
+ SimpleProblemCollector result = validate("bad-repository-id.xml");
+
+ assertViolations(result, 0, 4, 0);
+
+ assertContains(
+ result.getErrors().get(0), "'repositories.repository.id' must not contain any of these characters");
+ assertContains(
+ result.getErrors().get(1),
+ "'pluginRepositories.pluginRepository.id' must not contain any of these characters");
+ assertContains(
+ result.getErrors().get(2),
+ "'distributionManagement.repository.id' must not contain any of these characters");
+ assertContains(
+ result.getErrors().get(3),
+ "'distributionManagement.snapshotRepository.id' must not contain any of these characters");
+ }
+
@Test
public void testBadDependencyExclusionId() throws Exception {
SimpleProblemCollector result =
@@ -629,7 +698,8 @@ public void testBadImportScopeClassifier() throws Exception {
@Test
public void testSystemPathRefersToProjectBasedir() throws Exception {
- SimpleProblemCollector result = validateRaw("basedir-system-path.xml");
+ SimpleProblemCollector result =
+ validateRaw("basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
assertViolations(result, 0, 0, 2);
@@ -640,8 +710,7 @@ public void testSystemPathRefersToProjectBasedir() throws Exception {
result.getWarnings().get(1),
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory");
- SimpleProblemCollector result31 =
- validateRaw("basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1);
+ SimpleProblemCollector result31 = validateRaw("basedir-system-path.xml");
assertViolations(result31, 0, 0, 4);