This is an automated email from the ASF dual-hosted git repository.
slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 57b496f Fix #326: resolve a described plugin against plugin
repositories
57b496f is described below
commit 57b496fe7e9fa4027434b183b92fd941087ae3ea
Author: Arturo Bernal <[email protected]>
AuthorDate: Thu Oct 29 14:20:01 2026 +0100
Fix #326: resolve a described plugin against plugin repositories
AbstractHelpMojo.resolveArtifact() always resolved against
project.getRemoteProjectRepositories(). DescribeMojo calls it to
resolve a plugin's own jar/pom in two places: the fallback name
lookup when a plugin descriptor has no name, and isReportGoal()'s
check for whether a goal implements MavenReport. Both are resolving
the plugin itself, so a plugin published only to a <pluginRepository>
and not also declared as a project <repository> failed to resolve
there even though Maven resolved and ran the plugin fine during a
normal build.
Added a resolveArtifact(artifact, repositories) overload taking an
explicit repository list, with the existing resolveArtifact(artifact)
delegating to it with project repositories unchanged for its other
callers (getMavenProject, EvaluateMojo). DescribeMojo's three
plugin-resolution call sites now pass
project.getRemotePluginRepositories().
---
.../maven/plugins/help/AbstractHelpMojo.java | 26 +++++++++--
.../apache/maven/plugins/help/DescribeMojo.java | 9 ++--
.../maven/plugins/help/AbstractHelpMojoTest.java | 53 ++++++++++++++++++++++
.../maven/plugins/help/DescribeMojoTest.java | 40 ++++++++++++++++
4 files changed, 121 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
index ef4576f..651cc91 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
+import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelBuildingRequest;
@@ -36,6 +37,7 @@ import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
import org.eclipse.aether.resolution.ArtifactDescriptorResult;
import org.eclipse.aether.resolution.ArtifactRequest;
@@ -191,15 +193,31 @@ public abstract class AbstractHelpMojo extends
AbstractMojo {
protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact(
org.eclipse.aether.artifact.Artifact artifact) throws
RepositoryException {
+ return resolveArtifact(artifact,
project.getRemoteProjectRepositories());
+ }
+
+ /**
+ * Resolves the given artifact against an explicit list of remote
repositories, rather than the project's
+ * own {@code <repositories>}. Used to resolve a plugin's own artifact
against
+ * {@link MavenProject#getRemotePluginRepositories()}, since a plugin may
be published only to a
+ * {@code <pluginRepository>} and not also declared as a project {@code
<repository>}.
+ *
+ * @param artifact the artifact to resolve
+ * @param repositories the remote repositories to resolve the artifact
against
+ * @return the resolved artifact
+ * @throws RepositoryException if the artifact could not be resolved
+ * @since 3.5.3
+ */
+ protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact(
+ org.eclipse.aether.artifact.Artifact artifact,
List<RemoteRepository> repositories)
+ throws RepositoryException {
RepositorySystemSession repositorySession =
session.getRepositorySession();
// use descriptor to respect relocation
ArtifactDescriptorResult artifactDescriptor =
repositorySystem.readArtifactDescriptor(
- repositorySession,
- new ArtifactDescriptorRequest(artifact,
project.getRemoteProjectRepositories(), null));
+ repositorySession, new ArtifactDescriptorRequest(artifact,
repositories, null));
return repositorySystem.resolveArtifact(
- repositorySession,
- new ArtifactRequest(artifactDescriptor.getArtifact(),
project.getRemoteProjectRepositories(), null));
+ repositorySession, new
ArtifactRequest(artifactDescriptor.getArtifact(), repositories, null));
}
}
diff --git a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
index cfc8c29..ce502da 100644
--- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
@@ -403,7 +403,8 @@ public class DescribeMojo extends AbstractHelpMojo {
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
- Artifact artifactCopy =
resolveArtifact(aetherArtifact).getArtifact();
+ Artifact artifactCopy = resolveArtifact(aetherArtifact,
project.getRemotePluginRepositories())
+ .getArtifact();
name = projectBuilder
.build(RepositoryUtils.toArtifact(artifactCopy), pbr)
.getProject()
@@ -909,10 +910,12 @@ public class DescribeMojo extends AbstractHelpMojo {
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Artifact jar = resolveArtifact(
- new DefaultArtifact(pd.getGroupId(),
pd.getArtifactId(), "jar", pd.getVersion()))
+ new DefaultArtifact(pd.getGroupId(),
pd.getArtifactId(), "jar", pd.getVersion()),
+ project.getRemotePluginRepositories())
.getArtifact();
Artifact pom = resolveArtifact(
- new DefaultArtifact(pd.getGroupId(),
pd.getArtifactId(), "pom", pd.getVersion()))
+ new DefaultArtifact(pd.getGroupId(),
pd.getArtifactId(), "pom", pd.getVersion()),
+ project.getRemotePluginRepositories())
.getArtifact();
MavenProject mavenProject = projectBuilder.build(pom.getFile(),
pbr).getProject();
urls.add(jar.getFile().toURI().toURL());
diff --git
a/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java
b/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java
index fddea04..e307717 100644
--- a/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/AbstractHelpMojoTest.java
@@ -18,12 +18,29 @@
*/
package org.apache.maven.plugins.help;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
+import org.eclipse.aether.resolution.ArtifactDescriptorResult;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
/**
* Tests the coordinate parsing in {@link
AbstractHelpMojo#getAetherArtifact(String, String)}.
@@ -65,4 +82,40 @@ class AbstractHelpMojoTest {
void emptyCoordinatesAreRejected() {
assertThrows(IllegalArgumentException.class, () ->
mojo.getAetherArtifact("", "pom"));
}
+
+ @Test
+ void resolveArtifactWithExplicitRepositoriesUsesThoseRepositories() throws
Exception {
+ RepositorySystem repositorySystem = mock(RepositorySystem.class);
+ AbstractHelpMojo mojoWithExplicitRepos = new AbstractHelpMojo(null,
repositorySystem) {
+ @Override
+ public void execute() {}
+ };
+
+ MavenSession session = mock(MavenSession.class);
+
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
+ mojoWithExplicitRepos.session = session;
+
+ Artifact artifact = new DefaultArtifact("org.test:test-plugin:1.0");
+ ArtifactDescriptorResult descriptorResult =
+ new ArtifactDescriptorResult(new
ArtifactDescriptorRequest()).setArtifact(artifact);
+ when(repositorySystem.readArtifactDescriptor(any(),
any())).thenReturn(descriptorResult);
+ ArtifactResult artifactResult = new ArtifactResult(new
ArtifactRequest());
+ when(repositorySystem.resolveArtifact(any(),
any())).thenReturn(artifactResult);
+
+ List<RemoteRepository> pluginRepositories = Collections.singletonList(
+ new RemoteRepository.Builder("plugin-repo", "default",
"https://plugin.example/").build());
+
+ ArtifactResult result =
mojoWithExplicitRepos.resolveArtifact(artifact, pluginRepositories);
+
+ assertEquals(artifactResult, result);
+
+ ArgumentCaptor<ArtifactDescriptorRequest> descriptorCaptor =
+ ArgumentCaptor.forClass(ArtifactDescriptorRequest.class);
+ verify(repositorySystem).readArtifactDescriptor(any(),
descriptorCaptor.capture());
+ assertEquals(pluginRepositories,
descriptorCaptor.getValue().getRepositories());
+
+ ArgumentCaptor<ArtifactRequest> requestCaptor =
ArgumentCaptor.forClass(ArtifactRequest.class);
+ verify(repositorySystem).resolveArtifact(any(),
requestCaptor.capture());
+ assertEquals(pluginRepositories,
requestCaptor.getValue().getRepositories());
+ }
}
diff --git a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
index 01e880c..efaeae1 100644
--- a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
@@ -44,8 +44,11 @@ import org.apache.maven.plugin.version.PluginVersionRequest;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.plugin.version.PluginVersionResult;
import org.apache.maven.plugins.help.DescribeMojo.PluginInfo;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -408,6 +411,43 @@ class DescribeMojoTest {
}
}
+ @Test
+ void testDescribePluginResolvesMissingNameAgainstPluginRepositories()
throws Exception {
+ RepositorySystem repositorySystem = mock(RepositorySystem.class);
+ when(repositorySystem.readArtifactDescriptor(any(),
any())).thenThrow(new RuntimeException("not resolvable"));
+ DescribeMojo mojo = new DescribeMojo(null, repositorySystem, null,
null, null, null, null);
+
+ MavenSession session = mock(MavenSession.class);
+
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
+ when(session.getProjectBuildingRequest()).thenReturn(new
DefaultProjectBuildingRequest());
+ setParentFieldWithReflection(mojo, "session", session);
+
+ RemoteRepository projectRepo =
+ new RemoteRepository.Builder("project-repo", "default",
"https://project.example/").build();
+ RemoteRepository pluginRepo =
+ new RemoteRepository.Builder("plugin-repo", "default",
"https://plugin.example/").build();
+ MavenProject mavenProject = mock(MavenProject.class);
+
when(mavenProject.getRemoteProjectRepositories()).thenReturn(Collections.singletonList(projectRepo));
+
when(mavenProject.getRemotePluginRepositories()).thenReturn(Collections.singletonList(pluginRepo));
+ setParentFieldWithReflection(mojo, "project", mavenProject);
+
+ PluginDescriptor pd = new PluginDescriptor();
+ pd.setGroupId("org.test");
+ pd.setArtifactId("test-plugin");
+ pd.setVersion("1.0");
+ // pd.getName() stays null, which is what triggers the fallback
artifact resolution
+
+ Method describePlugin =
+ DescribeMojo.class.getDeclaredMethod("describePlugin",
PluginDescriptor.class, StringBuilder.class);
+ describePlugin.setAccessible(true);
+ describePlugin.invoke(mojo, pd, new StringBuilder());
+
+
ArgumentCaptor<org.eclipse.aether.resolution.ArtifactDescriptorRequest> captor =
+
ArgumentCaptor.forClass(org.eclipse.aether.resolution.ArtifactDescriptorRequest.class);
+ verify(repositorySystem).readArtifactDescriptor(any(),
captor.capture());
+ assertEquals(Collections.singletonList(pluginRepo),
captor.getValue().getRepositories());
+ }
+
/**
* Regression test for Maven 3.10.0 behavior where {@code
Lifecycle.getDefaultLifecyclePhases()}
* returns an empty map (not null) for the "default" lifecycle.