Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Maven user settings when initializing artifact resolver #35203

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading