Skip to content

Commit

Permalink
Pass Maven user settings when initializing artifact resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Aug 4, 2023
1 parent 0d3cb35 commit 3306eb9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3306eb9

Please sign in to comment.