From 7e89d0df77cd24fe7f7024782a7035d7a8c57775 Mon Sep 17 00:00:00 2001 From: Vaclav Haisman Date: Sun, 2 Aug 2026 18:49:38 +0200 Subject: [PATCH] Resolve classified POM artifacts from reactor ReactorReader treated every POM request as the project build POM, ignoring the classifier. Let classified POMs proceed through attached-artifact matching and cover the behavior with a focused regression test. --- .../java/org/apache/maven/ReactorReader.java | 3 +- .../org/apache/maven/ReactorReaderTest.java | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 maven-core/src/test/java/org/apache/maven/ReactorReaderTest.java diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java index 2a3ac7dfcab5..2b4c8ad8b8b2 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -129,7 +129,8 @@ public Model findModel(Artifact artifact) { // private File find(MavenProject project, Artifact artifact) { - if ("pom".equals(artifact.getExtension())) { + if ("pom".equals(artifact.getExtension()) + && (artifact.getClassifier() == null || artifact.getClassifier().isEmpty())) { return project.getFile(); } diff --git a/maven-core/src/test/java/org/apache/maven/ReactorReaderTest.java b/maven-core/src/test/java/org/apache/maven/ReactorReaderTest.java new file mode 100644 index 000000000000..3caa023b9421 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/ReactorReaderTest.java @@ -0,0 +1,79 @@ +/* + * 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. + */ +package org.apache.maven; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class ReactorReaderTest { + + @TempDir + Path tempDir; + + @Test + void classifiedPomShouldResolveToAttachedArtifact() throws Exception { + File projectPom = Files.createFile(tempDir.resolve("pom.xml")).toFile(); + File attachedPom = Files.createFile(tempDir.resolve("custom.pom")).toFile(); + + MavenProject project = new MavenProject(); + project.setGroupId("org.apache.maven.its.mdep590"); + project.setArtifactId("producer"); + project.setVersion("1.0-SNAPSHOT"); + project.setFile(projectPom); + project.setArtifact(newArtifact(null, projectPom)); + project.addAttachedArtifact(newArtifact("custom", attachedPom)); + + MavenSession session = mock(MavenSession.class); + when(session.getProjects()).thenReturn(Collections.singletonList(project)); + + ReactorReader reader = new ReactorReader(session); + + assertEquals( + attachedPom, + reader.findArtifact(new org.eclipse.aether.artifact.DefaultArtifact( + "org.apache.maven.its.mdep590:producer:pom:custom:1.0-SNAPSHOT"))); + } + + private static Artifact newArtifact(String classifier, File file) { + Artifact artifact = new DefaultArtifact( + "org.apache.maven.its.mdep590", + "producer", + "1.0-SNAPSHOT", + Artifact.SCOPE_COMPILE, + "pom", + classifier, + new DefaultArtifactHandler("pom")); + artifact.setFile(file); + return artifact; + } +}