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 4bdf9a1fe1 test: verify omitting version in dependencyManagement when
importing BOM (#13694) (#13715)
4bdf9a1fe1 is described below
commit 4bdf9a1fe1a7c03f4b6cac7a5b6eaaf0a426f34b
Author: CHARAN GOWDA M D <[email protected]>
AuthorDate: Mon Nov 9 18:04:48 2026 +0530
test: verify omitting version in dependencyManagement when importing BOM
(#13694) (#13715)
- Add tests in DefaultModelBuilderTest verifying omitting version in
dependencyManagement with exclusions in same POM and in child POMs
- Add assertions in DefaultDependencyManagementImporterTest verifying
exclusions are preserved when inheriting BOM version
Co-authored-by: Charan Gowda <[email protected]>
---
.../DefaultDependencyManagementImporterTest.java | 8 +
.../maven/impl/model/DefaultModelBuilderTest.java | 167 +++++++++++++++++++++
2 files changed, 175 insertions(+)
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java
index 434d56a22c..bdc14ddfb3 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultDependencyManagementImporterTest.java
@@ -22,6 +22,7 @@
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.DependencyManagement;
+import org.apache.maven.api.model.Exclusion;
import org.apache.maven.api.model.InputLocation;
import org.apache.maven.api.model.InputSource;
import org.apache.maven.api.model.Model;
@@ -152,6 +153,10 @@ void
testImportManagementInheritsVersionFromImportedBomWhenLocalEntryHasNoVersio
.groupId("org.junit.jupiter")
.artifactId("junit-jupiter-api")
.scope("provided")
+ .exclusions(List.of(Exclusion.newBuilder()
+ .groupId("org.junit.vintage")
+ .artifactId("junit-vintage-engine")
+ .build()))
.build();
Model target = Model.newBuilder()
@@ -183,5 +188,8 @@ void
testImportManagementInheritsVersionFromImportedBomWhenLocalEntryHasNoVersio
assertEquals("junit-jupiter-api", merged.getArtifactId());
assertEquals("5.10.0", merged.getVersion());
assertEquals("provided", merged.getScope());
+ assertEquals(1, merged.getExclusions().size());
+ assertEquals("org.junit.vintage",
merged.getExclusions().get(0).getGroupId());
+ assertEquals("junit-vintage-engine",
merged.getExclusions().get(0).getArtifactId());
}
}
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java
index e99cb7769d..4581080e3e 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java
@@ -1902,6 +1902,173 @@ static ApacheTransporterFactory
newApacheTransporterFactory(
return new ApacheTransporterFactory(checksumExtractor, pathProcessor);
}
+ @Test
+ public void testOmitVersionInDependencyManagementWithExclusion(@TempDir
Path tempDir) throws Exception {
+ Path basedir = Paths.get(System.getProperty("basedir", ""));
+ Path localRepoPath = tempDir.resolve("local-repo");
+ Path remoteRepoPath = basedir.resolve("src/test/remote-repo");
+ Session session = ApiRunner.createSession(
+ injector ->
injector.bindInstance(DefaultModelBuilderTest.class, this), localRepoPath);
+ RemoteRepository remoteRepository = session.createRemoteRepository(
+ RemoteRepository.CENTRAL_ID,
remoteRepoPath.toUri().toString());
+ session = session.withRemoteRepositories(List.of(remoteRepository));
+ ModelBuilder builder = session.getService(ModelBuilder.class);
+
+ Files.createDirectory(tempDir.resolve(".mvn"));
+ Path projectPom = tempDir.resolve("pom.xml");
+ String pomContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>test-project</artifactId>
+ <version>1.0</version>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>bom</artifactId>
+ <version>0.1</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>a</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>b</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>a</artifactId>
+ </dependency>
+ </dependencies>
+ </project>
+ """;
+ Files.writeString(projectPom, pomContent);
+
+ ModelBuilderResult result = builder.newSession()
+ .build(ModelBuilderRequest.builder()
+ .session(session)
+
.requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT)
+ .source(Sources.buildSource(projectPom))
+ .build());
+
+ assertNotNull(result);
+ Model model = result.getEffectiveModel();
+ assertNotNull(model);
+ Dependency dep = model.getDependencies().stream()
+ .filter(d -> "a".equals(d.getArtifactId()))
+ .findFirst()
+ .orElse(null);
+ assertNotNull(dep);
+ assertEquals("0.1", dep.getVersion());
+ assertEquals(1, dep.getExclusions().size());
+ assertEquals("b", dep.getExclusions().get(0).getArtifactId());
+ }
+
+ @Test
+ public void
testOmitVersionInDependencyManagementWithExclusionInChild(@TempDir Path
tempDir) throws Exception {
+ Path basedir = Paths.get(System.getProperty("basedir", ""));
+ Path localRepoPath = tempDir.resolve("local-repo");
+ Path remoteRepoPath = basedir.resolve("src/test/remote-repo");
+ Session session = ApiRunner.createSession(
+ injector ->
injector.bindInstance(DefaultModelBuilderTest.class, this), localRepoPath);
+ RemoteRepository remoteRepository = session.createRemoteRepository(
+ RemoteRepository.CENTRAL_ID,
remoteRepoPath.toUri().toString());
+ session = session.withRemoteRepositories(List.of(remoteRepository));
+ ModelBuilder builder = session.getService(ModelBuilder.class);
+
+ Files.createDirectory(tempDir.resolve(".mvn"));
+ Path parentPom = tempDir.resolve("pom.xml");
+ String parentContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>parent-project</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>bom</artifactId>
+ <version>0.1</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ </project>
+ """;
+ Files.writeString(parentPom, parentContent);
+
+ Path childDir = tempDir.resolve("child");
+ Files.createDirectory(childDir);
+ Path childPom = childDir.resolve("pom.xml");
+ String childContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>parent-project</artifactId>
+ <version>1.0</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>child-project</artifactId>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>a</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>b</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>a</artifactId>
+ </dependency>
+ </dependencies>
+ </project>
+ """;
+ Files.writeString(childPom, childContent);
+
+ ModelBuilderResult result = builder.newSession()
+ .build(ModelBuilderRequest.builder()
+ .session(session)
+
.requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT)
+ .source(Sources.buildSource(childPom))
+ .build());
+
+ assertNotNull(result);
+ Model model = result.getEffectiveModel();
+ assertNotNull(model);
+ Dependency dep = model.getDependencies().stream()
+ .filter(d -> "a".equals(d.getArtifactId()))
+ .findFirst()
+ .orElse(null);
+ assertNotNull(dep);
+ assertEquals("0.1", dep.getVersion());
+ assertEquals(1, dep.getExclusions().size());
+ assertEquals("b", dep.getExclusions().get(0).getArtifactId());
+ }
+
private Path getPom(String name) {
return Paths.get("src/test/resources/poms/factory/" + name +
".xml").toAbsolutePath();
}