Repository: quarkusio/quarkus
Issue: Quarkus build does not work since 3.2.0 with teamcity/plexus launcher

### Describe the bug

We have some custom extensions which use dependencies from a private repository. Since quarkus 3.2.0 the build fails while generating the test code. Up to 3.1.3 it worked fine.

```
  [INFO] --- quarkus:3.2.1.Final:generate-code-tests (default) @ database-extension-base ---
  [INFO] Artifact de.mobilexag.serviceplatform:service-parent-kotlin:pom:1.8.1 is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from [central (https://repo.maven.apache.org/maven2, default, releases)]
  Downloading from central: https://repo.maven.apache.org/maven2/de/mobilexag/serviceplatform/service-parent-kotlin/1.8.1/service-parent-kotlin-1.8.1.pom
  [INFO] No previous run data found, generating javadoc.
  Failed to execute goal io.quarkus:quarkus-maven-plugin:3.2.1.Final:generate-code-tests (default) on project database-extension-base: Quarkus code generation phase has failed
```

I first thought this might be the problem, but it fails still with 3.2.1 https://github.com/quarkusio/quarkus/issues/34448

We encountered the problem on our build system teamcity. It starts maven builds via the plexus launcher. https://codehaus-plexus.github.io/plexus-classworlds/launcher.html
The quarkus maven plugin seems to ignore the settings file set via plexus. The call looks something like this:

```
java -Dmaven.repo.local=local-repo \\
-Dclassworlds.conf=teamcity.m2.conf \\
-Dmaven.multiModuleProjectDirectory=../code-with-quarkus \\
 --add-opens \\
 java.base/java.lang=ALL-UNNAMED \\
 -classpath \\
 "$MAVEN_HOME/boot/*:" \\
 org.codehaus.plexus.classworlds.launcher.Launcher \\
 -f \\
 pom.xml \\
 -B \\
 -s \\
 custom-settings.xml \\
 -fae \\
 -Plicense \\
 -X \\
 clean \\
 package
```
The settings file is set via -s command on maven start.

In the reproducer, there are some scripts to start the build.

### Expected behavior

Build should work.

### Actual behavior

Build fails.

### How to Reproduce?

https://github.com/robp94/quarkus-3.2.x-maven-problem

### Output of `uname -a` or `ver`

ubuntu

### Output of `java -version`

17

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

3.2.2

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

maven 3.9.3

### Additional information

_No response_

Changed files:
devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java, devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java, devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java, devtools/maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java, devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java, devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java

diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java
index a990e5d8ccd..22891e8f44d 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/DependencyTreeMojo.java
@@ -8,6 +8,7 @@
 import java.util.List;
 import java.util.function.Consumer;
 
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -37,6 +38,9 @@ public class DependencyTreeMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project}", readonly = true, required = true)
     protected MavenProject project;
 
+    @Parameter(defaultValue = "${session}", readonly = true)
+    protected MavenSession session;
+
     @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true)
     private List<RemoteRepository> repos;
 
@@ -130,6 +134,7 @@ private void logTree(final Consumer<String> log) throws MojoExecutionException {
     protected MavenArtifactResolver resolver() {
         return resolver == null
                 ? resolver = workspaceProvider.createArtifactResolver(BootstrapMavenContext.config()
+                        .setUserSettings(session.getRequest().getUserSettingsFile())
                         // The system needs to be initialized with the bootstrap model builder to properly interpolate system properties set on the command line
                         // e.g. -Dquarkus.platform.version=xxx
                         //.setRepositorySystem(repoSystem)
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
index b06e1b16173..34d04f14e98 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
@@ -1137,6 +1137,7 @@ private QuarkusDevModeLauncher newLauncher(Boolean debugPortOk, String bootstrap
             bootstrapProvider.close();
         } else {
             final BootstrapMavenContextConfig<?> mvnConfig = BootstrapMavenContext.config()
+                    .setUserSettings(session.getRequest().getUserSettingsFile())
                     .setRemoteRepositories(repos)
                     .setWorkspaceDiscovery(true)
                     .setPreferPomsFromWorkspace(true)
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java
index 4502351c87d..d76dee2638e 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java
@@ -7,6 +7,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -43,6 +44,9 @@ public class GoOfflineMojo extends AbstractMojo {
     @Parameter(defaultValue = "${project}", readonly = true, required = true)
     MavenProject project;
 
+    @Parameter(defaultValue = "${session}", readonly = true)
+    MavenSession session;
+
     @Component
     RepositorySystem repoSystem;
 
@@ -118,6 +122,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
 
     private MavenArtifactResolver getResolver() throws MojoExecutionException {
         return workspaceProvider.createArtifactResolver(BootstrapMavenContext.config()
+                .setUserSettings(session.getRequest().getUserSettingsFile())
                 .setCurrentProject(project.getBasedir().toString())
                 .setRemoteRepositoryManager(remoteRepositoryManager)
                 .setRemoteRepositories(repos)
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java
index 36bcdf8908c..2ae61b88271 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java
@@ -180,6 +180,9 @@ private MavenArtifactResolver artifactResolver(QuarkusBootstrapMojo mojo, Launch
                 if (mode == LaunchMode.DEVELOPMENT || mode == LaunchMode.TEST || isWorkspaceDiscovery(mojo)) {
                     return workspaceProvider.createArtifactResolver(
                             BootstrapMavenContext.config()
+                                    // it's important to pass user settings in case the process was not launched using the original mvn script
+                                    // for example using org.codehaus.plexus.classworlds.launcher.Launcher
+                                    .setUserSettings(mojo.mavenSession().getRequest().getUserSettingsFile())
                                     .setCurrentProject(mojo.mavenProject().getFile().toString())
                                     .setPreferPomsFromWorkspace(true)
                                     .setProjectModelProvider(getProjectMap(mojo.mavenSession())::get));
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java
index 16043a4d5aa..62a7e1437ac 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectMojoBase.java
@@ -11,6 +11,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -52,6 +53,9 @@ public abstract class QuarkusProjectMojoBase extends AbstractMojo {
     @Parameter(defaultValue = "${project}")
     protected MavenProject project;
 
+    @Parameter(defaultValue = "${session}", readonly = true)
+    MavenSession session;
+
     @Component
     protected RepositorySystem repoSystem;
 
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java
index 9007e7315bb..62a346128a0 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java
@@ -140,6 +140,7 @@ protected MavenArtifactResolver catalogArtifactResolver() throws MojoExecutionEx
     @Override
     protected MavenArtifactResolver initArtifactResolver() throws MojoExecutionException {
         return workspaceProvider.createArtifactResolver(BootstrapMavenContext.config()
+                .setUserSettings(session.getRequest().getUserSettingsFile())
                 .setRemoteRepositoryManager(remoteRepositoryManager)
                 // The system needs to be initialized with the bootstrap model builder to properly interpolate system properties set on the command line
                 // e.g. -Dquarkus.platform.version=xxx