You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2026/07/30 13:38:53 UTC

(maven) branch fix-12604-settings-path created (now 03f982598d)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch fix-12604-settings-path
in repository https://gitbox.apache.org/repos/asf/maven.git


      at 03f982598d Fix #12604: DefaultSettingsBuilder dead Windows drive-relative path handling

This branch includes the following new commits:

     new 03f982598d Fix #12604: DefaultSettingsBuilder dead Windows drive-relative path handling

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven) 01/01: Fix #12604: DefaultSettingsBuilder dead Windows drive-relative path handling

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch fix-12604-settings-path
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 03f982598db6871ebc6858b75796bec3827b4765
Author: elharo <el...@users.noreply.github.com>
AuthorDate: Thu Jul 30 13:38:47 2026 +0000

    Fix #12604: DefaultSettingsBuilder dead Windows drive-relative path handling
    
    Remove the always-false condition !file.isAbsolute() && file.toString().startsWith(File.separator) which is dead code on all platforms - paths starting with the file separator are already absolute.
    
    Replace with !file.isAbsolute() (skipping paths containing ${} placeholders that need later interpolation). This correctly resolves all relative local repository paths to absolute, not just the never-reached Windows-specific case.
---
 .../java/org/apache/maven/impl/DefaultSettingsBuilder.java   |  7 ++++---
 .../apache/maven/impl/DefaultSettingsBuilderFactoryTest.java | 12 ++++++++++++
 .../test/resources/settings/settings-relative-local-repo.xml |  5 +++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java
index b5014498bf..498e739db1 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsBuilder.java
@@ -21,7 +21,6 @@
 import javax.xml.stream.Location;
 import javax.xml.stream.XMLStreamException;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Path;
@@ -128,11 +127,13 @@ public SettingsBuilderResult build(SettingsBuilderRequest request) throws Settin
                     .build();
         }
 
-        // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
+        // resolve relative local repository paths to absolute to save plugins from trouble.
+        // paths containing property placeholders like ${user.home} must be left as-is
+        // so that later interpolation can resolve them.
         String localRepository = effective.getLocalRepository();
         if (localRepository != null && !localRepository.isEmpty()) {
             Path file = Paths.get(localRepository);
-            if (!file.isAbsolute() && file.toString().startsWith(File.separator)) {
+            if (!file.isAbsolute() && !localRepository.contains("${")) {
                 effective = effective.withLocalRepository(file.toAbsolutePath().toString());
             }
         }
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java
index f76b9067be..f4a9fef365 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSettingsBuilderFactoryTest.java
@@ -42,6 +42,7 @@
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -160,6 +161,17 @@ void testSettingsWithDuplicateServersIds() throws Exception {
                 problems.problems().findFirst().orElseThrow().getMessage());
     }
 
+    @Test
+    void testRelativeLocalRepositoryIsResolvedToAbsolute() {
+        Settings settings = execute("settings-relative-local-repo").getEffectiveSettings();
+
+        String localRepository = settings.getLocalRepository();
+        assertNotNull(localRepository);
+        assertFalse(localRepository.isEmpty());
+        Path repoPath = Paths.get(localRepository);
+        assertTrue(repoPath.isAbsolute(), "Relative local repository should be resolved to absolute");
+    }
+
     private Path getSettings(String name) {
         return Paths.get("src/test/resources/settings/" + name + ".xml").toAbsolutePath();
     }
diff --git a/impl/maven-impl/src/test/resources/settings/settings-relative-local-repo.xml b/impl/maven-impl/src/test/resources/settings/settings-relative-local-repo.xml
new file mode 100644
index 0000000000..cf888feccf
--- /dev/null
+++ b/impl/maven-impl/src/test/resources/settings/settings-relative-local-repo.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<settings xmlns='http://maven.apache.org/SETTINGS/1.0.0'>
+  <localRepository>relative/repo</localRepository>
+</settings>