From c88c6cfa286b6d4314e762126a1bbd6abf28d6ee Mon Sep 17 00:00:00 2001 From: Mirko Friedenhagen Date: Fri, 19 Mar 2021 11:41:26 +0100 Subject: [PATCH] fix(resolve-ranges): fail properly on managed dep without version * `mvn validate` does choke on dependencies without versions. * However in managed dependencies a missing version is ignored. * resolve-ranges does throw a NPE, which is not helpful. * So fail with available coordinates to make fixing easier. * When the artifactId is missing in a managed dependency Maven core will aready fail. Resolve #442 --- .../invoker.properties | 2 ++ src/it/it-resolve-ranges-issue-442/pom.xml | 22 +++++++++++++++++++ .../it-resolve-ranges-issue-442/verify.groovy | 2 ++ .../mojo/versions/ResolveRangesMojo.java | 6 +++++ 4 files changed, 32 insertions(+) create mode 100644 src/it/it-resolve-ranges-issue-442/invoker.properties create mode 100644 src/it/it-resolve-ranges-issue-442/pom.xml create mode 100644 src/it/it-resolve-ranges-issue-442/verify.groovy diff --git a/src/it/it-resolve-ranges-issue-442/invoker.properties b/src/it/it-resolve-ranges-issue-442/invoker.properties new file mode 100644 index 0000000000..b4d5204b00 --- /dev/null +++ b/src/it/it-resolve-ranges-issue-442/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=-X ${project.groupId}:${project.artifactId}:${project.version}:resolve-ranges +invoker.buildResult=failure diff --git a/src/it/it-resolve-ranges-issue-442/pom.xml b/src/it/it-resolve-ranges-issue-442/pom.xml new file mode 100644 index 0000000000..0ab78962ff --- /dev/null +++ b/src/it/it-resolve-ranges-issue-442/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-resolve-ranges-issues-442 + 1.0 + pom + resolve-ranges IT issue 442 + + Test that resolve-range chokes (correctly) on missing version in dependencyManagement + + + + + junit + junit + + + + + diff --git a/src/it/it-resolve-ranges-issue-442/verify.groovy b/src/it/it-resolve-ranges-issue-442/verify.groovy new file mode 100644 index 0000000000..fae229f113 --- /dev/null +++ b/src/it/it-resolve-ranges-issue-442/verify.groovy @@ -0,0 +1,2 @@ +def buildLogFile = new File(basedir, "build.log") +assert buildLogFile.text.contains("MojoExecutionException: Found invalid managed dependency junit:junit:jar without a version") \ No newline at end of file diff --git a/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java b/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java index 00a6c50bfb..5ff16462aa 100644 --- a/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java @@ -26,6 +26,7 @@ import javax.xml.stream.XMLStreamException; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -214,6 +215,11 @@ private void resolveRanges( ModifiedPomXMLEventReader pom, Collection