Repository: quarkusio/quarkus
Issue: Custom settings.xml is not honored by Quarkus (1.3, 1.7) when the path is relative

Custom settings.xml is not honored by Quarkus when the path is relative. Workaround is to set absolute path to settings.xml.

Spotted that when was trying to run Quarkus QS again released productized bit on https://maven.repository.redhat.com/ga
Bits got downloaded but test execution printed "Downloading from central: https://repo.maven.apache.org/maven2/com/redhat/quarkus/quarkus-universe-bom/1.3.4.Final-redhat-00004/quarkus-universe-bom-1.3.4.Final-redhat-00004.pom"

Quarkus implements own handling related to maven artifacts, there is probably issue in Quarkus bootstrap resolver.
I can't say if the problem is related to just 1.3 series or this is in 1.7 as upstream bits are always in central.
@aloubyansky this is probably for you.

**Reproducer**
```
git clone --branch 1.3.4.Final https://github.com/quarkusio/quarkus-quickstarts.git
code settings.xml ## see bellow
mvn -s settings.xml -f quarkus-quickstarts/pom.xml -pl getting-started clean test \\
  -Dquarkus.platform.group-id=com.redhat.quarkus -Dquarkus.platform.artifact-id=quarkus-universe-bom \\
  -Dquarkus.platform.version=1.3.4.Final-redhat-00004 -Dquarkus-plugin.version=1.3.4.Final-redhat-00004 \\
  -Dmaven.repo.local=$PWD/local-repo
```

**Error:**
```
[INFO] Running org.acme.getting.started.GreetingResourceTest
Downloading from central: https://repo.maven.apache.org/maven2/com/redhat/quarkus/quarkus-universe-bom/1.3.4.Final-redhat-00004/quarkus-universe-bom-1.3.4.Final-redhat-00004.pom
[ERROR] Tests run: 2, Failures: 0, Errors: 1, Skipped: 1, Time elapsed: 0.875 s <<< FAILURE! - in org.acme.getting.started.GreetingResourceTest
[ERROR] testHelloEndpoint  Time elapsed: 0.013 s  <<< ERROR!
java.lang.RuntimeException: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for org.acme:getting-started::jar:1.0-SNAPSHOT
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to create the application model for org.acme:getting-started::jar:1.0-SNAPSHOT
Caused by: io.quarkus.bootstrap.resolver.AppModelResolverException: Failed to read descriptor of org.acme:getting-started:jar:1.0-SNAPSHOT
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.acme:getting-started:jar:1.0-SNAPSHOT
Caused by: org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact com.redhat.quarkus:quarkus-universe-bom:pom:1.3.4.Final-redhat-00004 in central (https://repo.maven.apache.org/maven2)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact com.redhat.quarkus:quarkus-universe-bom:pom:1.3.4.Final-redhat-00004 in central (https://repo.maven.apache.org/maven2)
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact com.redhat.quarkus:quarkus-universe-bom:pom:1.3.4.Final-redhat-00004 in central (https://repo.maven.apache.org/maven2)
```

**settings.xml**
```xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
        
    <localRepository/>

    <profiles>
        <profile>
            <id>rh</id>
            <repositories>
              <repository>
                <id>red-hat-enterprise-maven-repository</id>
                <url>https://maven.repository.redhat.com/ga/</url>
                <releases>
                  <enabled>true</enabled>
                </releases>
                <snapshots>
                  <enabled>false</enabled>
                </snapshots>
              </repository>
            </repositories>
            <pluginRepositories>
              <pluginRepository>
                <id>red-hat-enterprise-maven-repository</id>
                <url>https://maven.repository.redhat.com/ga/</url>
                <releases>
                  <enabled>true</enabled>
                </releases>
                <snapshots>
                  <enabled>false</enabled>
                </snapshots>
              </pluginRepository>
            </pluginRepositories>
          </profile>
    </profiles>
        
    <activeProfiles>
        <activeProfile>rh</activeProfile>
    </activeProfiles>
    
</settings>
```

**Workaround**
`mvn -s settings.xml` => `mvn -s $PWD/settings.xml`

Changed files:
independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java

diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java
index e055581cbd6..dcea225818d 100644
--- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java
+++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java
@@ -147,20 +147,7 @@ public BootstrapMavenContext(BootstrapMavenContextConfig<?> config)
             currentProject = resolveCurrentProject();
             this.workspace = currentProject == null ? null : currentProject.getWorkspace();
         }
-        userSettings = config.userSettings == null
-                ? resolveSettingsFile(getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_USER_SETTINGS),
-                        () -> {
-                            final String quarkusMavenSettings = PropertyUtils.getProperty(MAVEN_SETTINGS);
-                            return quarkusMavenSettings == null ? new File(userMavenConfigurationHome, SETTINGS_XML)
-                                    : new File(quarkusMavenSettings);
-                        })
-                : config.userSettings;
-        globalSettings = resolveSettingsFile(getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_GLOBAL_SETTINGS),
-                () -> {
-                    final String envM2Home = System.getenv(MAVEN_HOME);
-                    return new File(PropertyUtils.getProperty(MAVEN_DOT_HOME, envM2Home != null ? envM2Home : ""),
-                            "conf/settings.xml");
-                });
+        userSettings = config.userSettings;
     }
 
     public AppArtifact getCurrentProjectArtifact(String extension) throws BootstrapMavenException {
@@ -188,11 +175,27 @@ public BootstrapMavenOptions getCliOptions() {
     }
 
     public File getUserSettings() {
-        return userSettings;
+        return userSettings == null
+                ? userSettings = resolveSettingsFile(
+                        getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_USER_SETTINGS),
+                        () -> {
+                            final String quarkusMavenSettings = PropertyUtils.getProperty(MAVEN_SETTINGS);
+                            return quarkusMavenSettings == null ? new File(userMavenConfigurationHome, SETTINGS_XML)
+                                    : new File(quarkusMavenSettings);
+                        })
+                : userSettings;
     }
 
     public File getGlobalSettings() {
-        return globalSettings;
+        return globalSettings == null
+                ? globalSettings = resolveSettingsFile(
+                        getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_GLOBAL_SETTINGS),
+                        () -> {
+                            final String envM2Home = System.getenv(MAVEN_HOME);
+                            return new File(PropertyUtils.getProperty(MAVEN_DOT_HOME, envM2Home != null ? envM2Home : ""),
+                                    "conf/settings.xml");
+                        })
+                : globalSettings;
     }
 
     public boolean isOffline() throws BootstrapMavenException {
@@ -270,27 +273,43 @@ public static String resolveLocalRepo(Settings settings) {
         return localRepo == null ? new File(userMavenConfigurationHome, "repository").getAbsolutePath() : localRepo;
     }
 
-    private static File resolveSettingsFile(String settingsArg, Supplier<File> supplier) {
+    private File resolveSettingsFile(String settingsArg, Supplier<File> supplier) {
         File userSettings;
         if (settingsArg != null) {
             userSettings = new File(settingsArg);
             if (userSettings.exists()) {
                 return userSettings;
             }
-            String base = System.getenv("MAVEN_PROJECTBASEDIR"); // Root project base dir
-            if (base != null) {
-                userSettings = new File(base, settingsArg);
-                if (userSettings.exists()) {
-                    return userSettings;
-                }
+            if (userSettings.isAbsolute()) {
+                return null;
             }
-            base = PropertyUtils.getProperty(BASEDIR); // current module project base dir
-            if (base != null) {
-                userSettings = new File(base, settingsArg);
-                if (userSettings.exists()) {
-                    return userSettings;
+
+            // in case the settings path is a relative one we check whether the pom path is also a relative one
+            // in which case we can resolve the settings path relative to the project directory
+            // otherwise, we don't have a clue what the settings path is relative to
+            String alternatePomDir = getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_POM_FILE);
+            if (alternatePomDir != null) {
+                File tmp = new File(alternatePomDir);
+                if (tmp.isAbsolute()) {
+                    alternatePomDir = null;
+                } else {
+                    if (!tmp.isDirectory()) {
+                        tmp = tmp.getParentFile();
+                    }
+                    alternatePomDir = tmp.toString();
                 }
             }
+
+            // Root project base dir
+            userSettings = resolveSettingsFile(settingsArg, alternatePomDir, System.getenv("MAVEN_PROJECTBASEDIR"));
+            if (userSettings != null) {
+                return userSettings;
+            }
+            // current module project base dir
+            userSettings = resolveSettingsFile(settingsArg, alternatePomDir, PropertyUtils.getProperty(BASEDIR));
+            if (userSettings != null) {
+                return userSettings;
+            }
             userSettings = new File(PropertyUtils.getUserHome(), settingsArg);
             if (userSettings.exists()) {
                 return userSettings;
@@ -300,6 +319,25 @@ private static File resolveSettingsFile(String settingsArg, Supplier<File> suppl
         return userSettings.exists() ? userSettings : null;
     }
 
+    private File resolveSettingsFile(String settingsArg, String alternatePomDir, String projectBaseDir) {
+        if (projectBaseDir == null) {
+            return null;
+        }
+        File userSettings;
+        if (alternatePomDir != null && projectBaseDir.endsWith(alternatePomDir)) {
+            userSettings = new File(projectBaseDir.substring(0, projectBaseDir.length() - alternatePomDir.length()),
+                    settingsArg);
+            if (userSettings.exists()) {
+                return userSettings;
+            }
+        }
+        userSettings = new File(projectBaseDir, settingsArg);
+        if (userSettings.exists()) {
+            return userSettings;
+        }
+        return null;
+    }
+
     private DefaultRepositorySystemSession newRepositorySystemSession() throws BootstrapMavenException {
         final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
         final Settings settings = getEffectiveSettings();