Skip to content

Commit

Permalink
fix(resolve-ranges): fail properly on managed dep without version
Browse files Browse the repository at this point in the history
 * `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
  • Loading branch information
mfriedenhagen committed Mar 19, 2021
1 parent cee63d8 commit c88c6cf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions src/it/it-resolve-ranges-issue-442/pom.xml
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>localhost</groupId>
<artifactId>it-resolve-ranges-issues-442</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>resolve-ranges IT issue 442</name>

<description>Test that resolve-range chokes (correctly) on missing version in dependencyManagement</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</dependencyManagement>

</project>
2 changes: 2 additions & 0 deletions 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")
Expand Up @@ -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;
Expand Down Expand Up @@ -214,6 +215,11 @@ private void resolveRanges( ModifiedPomXMLEventReader pom, Collection<Dependency
continue;
}

if ( StringUtils.isBlank( dep.getVersion() ) )
{
throw new MojoExecutionException( "Found invalid managed dependency " + toString( dep ) + " without a version");
}

if ( isHandledByProperty( dep ) )
{
getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) );
Expand Down

0 comments on commit c88c6cf

Please sign in to comment.