From 3306eb930024c8726c53e02e4532805b33e9b369 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Fri, 4 Aug 2023 14:29:19 +0200 Subject: [PATCH] Pass Maven user settings when initializing artifact resolver --- .../src/main/java/io/quarkus/maven/DependencyTreeMojo.java | 5 +++++ devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java | 1 + .../maven/src/main/java/io/quarkus/maven/GoOfflineMojo.java | 5 +++++ .../main/java/io/quarkus/maven/QuarkusBootstrapProvider.java | 3 +++ .../main/java/io/quarkus/maven/QuarkusProjectMojoBase.java | 4 ++++ .../java/io/quarkus/maven/QuarkusProjectStateMojoBase.java | 1 + 6 files changed, 19 insertions(+) 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 a990e5d8ccdef..22891e8f44de4 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 repos; @@ -130,6 +134,7 @@ private void logTree(final Consumer 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 b06e1b16173dc..34d04f14e98d9 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 4502351c87d9b..d76dee2638e73 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 36bcdf8908ca3..2ae61b88271c5 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 16043a4d5aa76..62a7e1437acf6 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 9007e7315bb61..62a346128a09c 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