This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 36fba7f4 Skip artifacts without a file in dependency:properties (#1655)
36fba7f4 is described below
commit 36fba7f4abd6ca8dfc9ee0426a6f3bfccc0df95f
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Thu Oct 29 05:27:32 2026 +0000
Skip artifacts without a file in dependency:properties (#1655)
Fixes #1647
Co-authored-by: Sylwester Lachiewicz <[email protected]>
---
.../maven/plugins/dependency/PropertiesMojo.java | 27 +++++++++++++---------
.../plugins/dependency/TestPropertiesMojo.java | 20 ++++++++++++++++
2 files changed, 36 insertions(+), 11 deletions(-)
diff --git
a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
index 363446d5..25ccea6a 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.dependency;
import javax.inject.Inject;
+import java.io.File;
import java.util.List;
import java.util.Set;
@@ -44,13 +45,11 @@ import
org.eclipse.aether.resolution.ArtifactResolutionException;
* @author Paul Gier
* @since 2.2
*/
-// CHECKSTYLE_OFF: LineLength
@Mojo(
name = "properties",
requiresDependencyResolution = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.INITIALIZE,
threadSafe = true)
-// CHECKSTYLE_ON: LineLength
public class PropertiesMojo extends AbstractMojo {
/**
@@ -112,16 +111,18 @@ public class PropertiesMojo extends AbstractMojo {
Set<Artifact> artifacts = project.getArtifacts();
for (Artifact artifact : artifacts) {
- project.getProperties()
- .setProperty(
- artifact.getDependencyConflictId(),
- artifact.getFile().getAbsolutePath());
+ String conflictId = artifact.getDependencyConflictId();
+ File file = artifact.getFile();
+ if (file != null) {
+ project.getProperties().setProperty(conflictId,
file.getAbsolutePath());
+ } else {
+ getLog().warn("Artifact " + conflictId + " has no associated
file; no property will be set for it.");
+ }
}
if (extraArtifacts != null) {
try {
for (ParamArtifact paramArtifact : extraArtifacts) {
-
if (!paramArtifact.isDataSet()) {
throw new MojoExecutionException("You must specify an
artifact OR GAV separately");
}
@@ -130,10 +131,14 @@ public class PropertiesMojo extends AbstractMojo {
resolverUtil.createArtifactFromParams(paramArtifact);
artifact = resolverUtil.resolveArtifact(artifact,
project.getRemoteProjectRepositories());
- this.project
- .getProperties()
- .setProperty(
- toConflictId(artifact),
artifact.getFile().getAbsolutePath());
+ String conflictId = toConflictId(artifact);
+ File file = artifact.getFile();
+ if (file != null) {
+ this.project.getProperties().setProperty(conflictId,
file.getAbsolutePath());
+ } else {
+ getLog().warn("Extra artifact " + conflictId
+ + " has no associated file; no property will
be set for it.");
+ }
}
} catch (ArtifactResolutionException | ArtifactDescriptorException
e) {
throw new MojoExecutionException("Couldn't download artifact:
" + e.getMessage(), e);
diff --git
a/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java
b/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java
index 3d163d5c..12e40c7b 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/TestPropertiesMojo.java
@@ -29,13 +29,17 @@ 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.plugin.logging.Log;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@MojoTest(realRepositorySession = true)
@@ -102,4 +106,20 @@ class TestPropertiesMojo {
assertTrue(project.getProperties().containsKey(depId2));
assertTrue(new
File(project.getProperties().getProperty(depId1)).exists());
}
+
+ @Test
+ @InjectMojo(goal = "properties")
+ void testNullFileSkipsProperty(PropertiesMojo mojo) throws Exception {
+ Artifact artifact = Mockito.mock(Artifact.class);
+ when(artifact.getDependencyConflictId()).thenReturn("group:artifact");
+ when(artifact.getFile()).thenReturn(null);
+ when(this.project.getArtifacts()).thenReturn(new
HashSet<>(Arrays.asList(artifact)));
+ Log log = Mockito.mock(Log.class);
+ mojo.setLog(log);
+
+ mojo.execute();
+
+ assertFalse(project.getProperties().containsKey("group:artifact"));
+ verify(log).warn(contains("group:artifact"));
+ }
}