Skip to content
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.

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

fix(resolve-ranges): fail properly on managed dep without version #452

Merged
merged 1 commit into from Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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