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 828acc62c9 Fix reactor parent resolution from profile repositories
(#13809) (#13846)
828acc62c9 is described below
commit 828acc62c9814ca6745b4ea5ad323372efe0350d
Author: Goutam Adwant <[email protected]>
AuthorDate: Fri Nov 6 13:10:56 2026 -0800
Fix reactor parent resolution from profile repositories (#13809) (#13846)
---
.../maven/impl/model/DefaultModelBuilder.java | 14 ++-
.../maven/impl/model/ParentTraversalTest.java | 104 +++++++++++++++++++++
...h13809ParentResolutionFromProfileReposTest.java | 72 ++++++++++++++
.../child/pom.xml | 29 ++++++
.../pom-template.xml | 46 +++++++++
.../repo/.gitattributes | 1 +
.../parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom | 26 ++++++
.../1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom.sha1 | 1 +
8 files changed, 292 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
index 179ac110e2..c67cfaba48 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
@@ -2508,8 +2508,20 @@ ParentFrame advance(Set<ModelSource> activeSources,
Set<ResolvedParentKey> activ
}
recording = context.start();
model = readRawModel();
+ Model parentResolutionModel = model;
+ if (model.getProfiles().stream()
+ .anyMatch(p ->
!p.getRepositories().isEmpty())) {
+ // Parent lookup needs profile repositories
before assembling the ancestry.
+ // Keep final profile injection after
inheritance, using the child's context.
+ DefaultProfileActivationContext activation =
recording.start(model.getProperties());
+ List<Profile> profiles =
getActiveProfiles(model.getProfiles(), activation);
+ replayRecordIntoContext(activation.stop(),
recording, false);
+ parentResolutionModel =
profileInjector.injectProfiles(
+ model, profiles, request,
ModelBuilderSessionState.this);
+ }
phase = ParentModelPhase.PARENT;
- return new ParentResolutionFrame(model,
model.getParent(), recording, chain, true, false);
+ return new ParentResolutionFrame(
+ parentResolutionModel, model.getParent(),
recording, chain, true, false);
}
}
case PARENT -> {
diff --git
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ParentTraversalTest.java
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ParentTraversalTest.java
index e39c77b5a0..bb9a4ed3c2 100644
---
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ParentTraversalTest.java
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/ParentTraversalTest.java
@@ -29,7 +29,9 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.di.Priority;
import org.apache.maven.api.di.Provides;
@@ -94,6 +96,108 @@ void testDeepParentsPreserveProfilesAndCache(@TempDir Path
directory) throws Exc
assertEquals(Set.of("caller"), chain);
}
+ @Test
+ void
testParentProfileRepositoryIsAvailableBeforeAncestorResolution(@TempDir Path
directory) throws Exception {
+ Path pom = parentWithRepositoryProfiles(
+ directory,
+ repositoryProfile(
+ "test-profile",
+ "",
+
"<properties><repo.url>file:///profile-repository</repo.url></properties>"));
+ AtomicInteger resolutions = repositoryResolver(directory,
Map.of("test-profile", "file:///profile-repository"));
+ var state = builder.new
ModelBuilderSessionState(ModelBuilderRequest.builder()
+ .session(session)
+ .source(Sources.buildSource(pom))
+ .requestType(ModelBuilderRequest.RequestType.BUILD_EFFECTIVE)
+ .activeProfileIds(List.of("test-profile"))
+ .build());
+ var activation = context(List.of("test-profile"), List.of()).start();
+ Model model = state.readAsParentModel(activation, new
LinkedHashSet<>());
+ assertEquals("file:///profile-repository",
model.getProperties().get("repo.url"));
+ assertEquals(Boolean.TRUE,
activation.stop().usedActiveProfiles.get("test-profile"));
+ assertEquals(1, resolutions.get());
+ assertSame(model,
state.readAsParentModel(context(List.of("test-profile"), List.of()), new
LinkedHashSet<>()));
+ assertEquals(1, resolutions.get(), "A matching activation context
should reuse the assembled parent");
+ }
+
+ @Test
+ void testExternalParentRepositoryProfilesRemainSandboxed(@TempDir Path
directory) throws Exception {
+ String profiles = repositoryProfile("test-jdk", "<jdk>[1,)</jdk>", "")
+ + repositoryProfile("test-user",
"<property><name>enable.repo</name></property>", "")
+ + repositoryProfile("test-file",
"<file><exists>${some.dir}</exists></file>", "")
+ + repositoryProfile("test-missing",
"<file><missing>missing-file</missing></file>", "")
+ + repositoryProfile("test-condition",
"<condition>missing('missing-file')</condition>", "");
+ Path pom = parentWithRepositoryProfiles(directory, profiles);
+ AtomicInteger resolutions = repositoryResolver(directory,
Map.of("test-jdk", "file:///default-repository"));
+ Map<String, String> systemProperties =
+ Map.of("java.version", System.getProperty("java.version"),
"some.dir", directory.toString());
+ Map<String, String> userProperties = Map.of("enable.repo", "true");
+ var state = builder.new
ModelBuilderSessionState(ModelBuilderRequest.builder()
+ .session(session)
+ .source(Sources.resolvedSource(pom, "test:parent:1"))
+
.requestType(ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY)
+ .systemProperties(systemProperties)
+ .userProperties(userProperties)
+ .build());
+ var activation = new DefaultProfileActivationContext(
+ session.getService(RootLocator.class),
+ session.getService(Interpolator.class),
+ List.of(),
+ List.of(),
+ systemProperties,
+ userProperties,
+ Model.newBuilder().pomFile(pom).build());
+ state.readAsParentModel(activation, new LinkedHashSet<>());
+ assertEquals(1, resolutions.get());
+ }
+
+ private AtomicInteger repositoryResolver(Path directory, Map<String,
String> expectedRepositories) {
+ AtomicInteger resolutions = new AtomicInteger();
+ ModelResolver resolver = mock(ModelResolver.class);
+
when(resolver.resolveModel(any(ModelResolver.ModelResolverRequest.class)))
+ .thenAnswer(invocation -> {
+ resolutions.incrementAndGet();
+ ModelResolver.ModelResolverRequest request =
invocation.getArgument(0);
+ assertEquals(
+ expectedRepositories,
+ request.repositories().stream()
+ .filter(repository ->
repository.id().startsWith("test-"))
+
.collect(Collectors.toMap(RemoteRepository::id, RemoteRepository::url)));
+ return new ModelResolver.ModelResolverResult(
+ request,
+
Sources.resolvedSource(directory.resolve("ancestor.xml"), "test:ancestor:1"),
+ null);
+ });
+ bindExternalResolver(resolver);
+ return resolutions;
+ }
+
+ private Path parentWithRepositoryProfiles(Path directory, String profiles)
throws IOException {
+ Files.writeString(directory.resolve("ancestor.xml"), """
+ <project><modelVersion>4.0.0</modelVersion>
+
<groupId>test</groupId><artifactId>ancestor</artifactId><version>1</version><packaging>pom</packaging>
+ </project>
+ """);
+ Path pom = directory.resolve("pom.xml");
+ Files.writeString(pom, """
+ <project
xmlns="http://maven.apache.org/POM/4.1.0"><modelVersion>4.1.0</modelVersion>
+
<parent><groupId>test</groupId><artifactId>ancestor</artifactId><version>1</version><relativePath/></parent>
+
<groupId>test</groupId><artifactId>parent</artifactId><version>1</version><packaging>pom</packaging>
+
<properties><repo.url>file:///default-repository</repo.url></properties>
+ <profiles>%s</profiles>
+ </project>
+ """.formatted(profiles));
+ return pom;
+ }
+
+ private String repositoryProfile(String id, String activation, String
properties) {
+ return """
+ <profile><id>%s</id><activation>%s</activation>%s
+
<repositories><repository><id>%s</id><url>${repo.url}</url></repository></repositories>
+ </profile>
+ """.formatted(id, activation, properties, id);
+ }
+
@Test
void testFailedReadRestoresCallerAncestry(@TempDir Path directory) throws
Exception {
Path pom = hierarchy(directory, 10, true);
diff --git
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13809ParentResolutionFromProfileReposTest.java
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13809ParentResolutionFromProfileReposTest.java
new file mode 100644
index 0000000000..99e1433f08
--- /dev/null
+++
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13809ParentResolutionFromProfileReposTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.it;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class MavenITgh13809ParentResolutionFromProfileReposTest extends
AbstractMavenIntegrationTestCase {
+
+ @Test
+ void testExplicitProfileInReactor() throws Exception {
+ Verifier verifier = verifier("explicit");
+ verifier.addCliArgument("-Pparent-repository");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+
+ @Test
+ void testPropertyActivatedProfileInReactor() throws Exception {
+ Verifier verifier = verifier("property");
+ verifier.addCliArgument("-Dparent.repository=true");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+
+ @Test
+ void testNonRecursiveBuild() throws Exception {
+ Verifier verifier = verifier("nonrecursive");
+ verifier.addCliArgument("-Pparent-repository");
+ verifier.addCliArgument("-N");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+
+ @Test
+ void testInactiveProfileDoesNotProvideRepository() throws Exception {
+ Verifier verifier = verifier("inactive");
+ assertThrows(VerificationException.class, verifier::execute);
+ verifier.verifyTextInLog("Non-resolvable parent POM");
+ }
+
+ private Verifier verifier(String name) throws Exception {
+ Path testDir = extractResources("gh-13809-parent-profile-repository");
+ Verifier verifier = newVerifier(testDir);
+ verifier.setAutoclean(false);
+ verifier.deleteDirectory("local-repo-" + name);
+ verifier.setLogFileName("log-" + name + ".txt");
+ verifier.filterFile("pom-template.xml", "pom.xml");
+ verifier.addCliArgument("-Dmaven.repo.local=" +
testDir.resolve("local-repo-" + name));
+ verifier.addCliArgument("validate");
+ return verifier;
+ }
+}
diff --git
a/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/child/pom.xml
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/child/pom.xml
new file mode 100644
index 0000000000..e12cce8d85
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/child/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its.gh13809</groupId>
+ <artifactId>root</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>child</artifactId>
+ <packaging>pom</packaging>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/pom-template.xml
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/pom-template.xml
new file mode 100644
index 0000000000..c630f4d9c0
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/pom-template.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.its.gh13809</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath />
+ </parent>
+ <artifactId>root</artifactId>
+ <packaging>pom</packaging>
+ <modules><module>child</module></modules>
+ <profiles>
+ <profile>
+ <id>parent-repository</id>
+
<activation><property><name>parent.repository</name></property></activation>
+
<properties><parent.repository.url>@baseurl@/repo</parent.repository.url></properties>
+ <repositories>
+ <repository>
+ <id>parent-repository</id>
+ <url>${parent.repository.url}</url>
+ <releases><enabled>false</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+ </profile>
+ </profiles>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/.gitattributes
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/.gitattributes
new file mode 100644
index 0000000000..eb4d40ce69
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/.gitattributes
@@ -0,0 +1 @@
+*.pom -text
diff --git
a/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom
new file mode 100644
index 0000000000..7b5807e33c
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.gh13809</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+</project>
diff --git
a/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom.sha1
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom.sha1
new file mode 100644
index 0000000000..8758343b83
--- /dev/null
+++
b/its/core-it-suite/src/test/resources/gh-13809-parent-profile-repository/repo/org/apache/maven/its/gh13809/parent/1.0-SNAPSHOT/parent-1.0-SNAPSHOT.pom.sha1
@@ -0,0 +1 @@
+f83027b3bbf28e46ee04ebb8aa0b4de4efd8e839