GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added ability to provide arbitrary dependencies to properties mojo by treilhes · Pull Request #1561 · apache/maven-dependency-plugin

Added ability to provide arbitrary dependencies to properties mojo #1561

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.

Sign up for GitHub

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

Merged
slawekjaranowski merged 2 commits into apache:master from treilhes:master
May 7, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Added ability to provide arbitrary dependencies to properties mojo #1561

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
9109760
Added ability to provide arbitrary dependencies to properties mojo
treilhes Nov 18, 2025
6a5ea10
fix spotless violation
treilhes May 7, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

71 changes: 69 additions & 2 deletions 71 src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;

import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
Expand All @@ -29,7 +30,10 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.dependency.utils.ParamArtifact;
import org.apache.maven.plugins.dependency.utils.ResolverUtil;
import org.apache.maven.project.MavenProject;
import org.eclipse.aether.resolution.ArtifactResolutionException;

/**
* Goal that sets a property pointing to the artifact file for each project dependency. For each dependency (direct and
Expand All @@ -53,9 +57,12 @@ public class PropertiesMojo extends AbstractMojo {
*/
private final MavenProject project;

private final ResolverUtil resolverUtil;

@Inject
public PropertiesMojo(MavenProject project) {
public PropertiesMojo(MavenProject project, ResolverUtil resolverUtil) {
this.project = project;
this.resolverUtil = resolverUtil;
}

/**
Expand All @@ -67,8 +74,31 @@ public PropertiesMojo(MavenProject project) {
private boolean skip;

/**
* Main entry into mojo. Gets the list of dependencies and iterates through setting a property for each artifact.
* Extra artifacts that can be provided to the plugin. For each artifact in this list a property will be set
* similar to the project artifacts discovered. This allows callers to supply additional
* resolved dependencies for which properties pointing to the artifact file shall be created.
*
* Example usage in plugin configuration:
* <pre>
* &lt;extraArtifacts&gt;
* &lt;extraArtifact&gt;
* &lt;artifact&gt;org.example:my-artifact:jar:1.0&lt;/artifact&gt;
* &lt;/extraArtifact&gt;
* &lt;extraArtifact&gt;
* &lt;groupId&gt;org.example&lt;/groupId&gt;
* &lt;artifactId&gt;my-artifact&lt;/artifactId&gt;
* &lt;version&gt;1.0&lt;/version&gt;
* &lt;/extraArtifact&gt;
* &lt;/extraArtifacts&gt;
* </pre>
* @since 3.10.1
*/
@Parameter
private List<ParamArtifact> extraArtifacts;

/**
* Main entry into mojo. Gets the list of dependencies and iterates through setting a property for each artifact.
* Gets the list of declared plugin's extra artifacts and iterates through setting a property for each artifact.
* @throws MojoExecutionException with a message if an error occurs
*/
@Override
Expand All @@ -86,6 +116,28 @@ public void execute() throws MojoExecutionException {
artifact.getDependencyConflictId(),
artifact.getFile().getAbsolutePath());
}

if (extraArtifacts != null) {
try {
for (ParamArtifact paramArtifact : extraArtifacts) {

if (!paramArtifact.isDataSet()) {
throw new MojoExecutionException("You must specify an artifact OR GAV separately");
}

org.eclipse.aether.artifact.Artifact artifact =
resolverUtil.createArtifactFromParams(paramArtifact);
artifact = resolverUtil.resolveArtifact(artifact, project.getRemoteProjectRepositories());

this.project
.getProperties()
.setProperty(
toConflictId(artifact), artifact.getFile().getAbsolutePath());
}
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
}

/**
Expand All @@ -94,4 +146,19 @@ public void execute() throws MojoExecutionException {
public boolean isSkip() {
return skip;
}

private String toConflictId(org.eclipse.aether.artifact.Artifact artifact) {
// The conflict ID is the same as the one used by Maven's Artifact class, which is
// groupId:artifactId:type[:classifier]
StringBuilder sb = new StringBuilder();
sb.append(artifact.getGroupId())
.append(":")
.append(artifact.getArtifactId())
.append(":")
.append(artifact.getExtension());
if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
sb.append(":").append(artifact.getClassifier());
}
return sb.toString();
}
}
45 changes: 42 additions & 3 deletions 45 src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,30 @@
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoExtension;
import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.dependency.utils.ParamArtifact;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.ReflectionUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

@MojoTest
public class TestPropertiesMojo {
@MojoTest(realRepositorySession = true)
class TestPropertiesMojo {

@Inject
private MavenProject project;

@Test
@InjectMojo(goal = "properties")
public void testSetProperties(PropertiesMojo mojo) throws Exception {
void testSetProperties(PropertiesMojo mojo) throws Exception {

Artifact artifact1 = Mockito.mock(Artifact.class);
Artifact artifact2 = Mockito.mock(Artifact.class);
Expand All @@ -63,4 +66,40 @@ public void testSetProperties(PropertiesMojo mojo) throws Exception {
assertTrue(project.getProperties().getProperty("group1:artifact1").endsWith("artifact1.jar"));
assertTrue(project.getProperties().getProperty("group2:artifact2").endsWith("artifact2.jar"));
}

/**
* tests the proper discovery and configuration of the mojo for extra artifacts
* Each artifact should be resolved and set a property in the project
* @throws Exception in case of errors
*/
@Test
@InjectMojo(goal = "properties")
void testSetPropertiesForExtractArtifacts(PropertiesMojo mojo) throws Exception {

String depId1 = "org.apache.commons:commons-lang3:jar";
String depId2 = "org.apache.commons:commons-collections4:jar";

ParamArtifact a1 = new ParamArtifact();
a1.setGroupId("org.apache.commons");
a1.setArtifactId("commons-lang3");
a1.setVersion("3.6");

ParamArtifact a2 = new ParamArtifact();
a2.setGroupId("org.apache.commons");
a2.setArtifactId("commons-collections4");
a2.setVersion("4.4");

List<ParamArtifact> artifacts = Arrays.asList(a1, a2);

// 3. Inject into private field
ReflectionUtils.setVariableValueInObject(mojo, "extraArtifacts", artifacts);

mojo.execute();

assertTrue(project.getProperties().containsKey(depId1));
assertTrue(new File(project.getProperties().getProperty(depId1)).exists());

assertTrue(project.getProperties().containsKey(depId2));
assertTrue(new File(project.getProperties().getProperty(depId1)).exists());
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.