[MNG-4427] Bad error message with duplicate dependencies that don't declare a version

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@833040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-11-05 12:37:30 +00:00
parent 61ba8778b6
commit c980cfb28d
2 changed files with 18 additions and 15 deletions

View File

@ -69,20 +69,19 @@ public class DefaultModelNormalizer
build.setPlugins( new ArrayList<Plugin>( normalized.values() ) );
}
if ( request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 )
/*
* NOTE: This is primarily to keep backward-compat with Maven 2.x which did not validate that dependencies are
* unique within a single POM. Upon multiple declarations, 2.x just kept the last one but retained the order of
* the first occurrence. So when we're in lenient/compat mode, we have to deal with such broken POMs and mimic
* the way 2.x works. When we're in strict mode, the removal of duplicates just saves other merging steps from
* aftereffects and bogus error messages.
*/
Map<String, Dependency> dependencies = new LinkedHashMap<String, Dependency>();
for ( Dependency dependency : model.getDependencies() )
{
/*
* NOTE: This is to keep backward-compat with Maven 2.x which did not validate that dependencies are unique
* within a single POM. Upon multiple declarations, 2.x just kept the last one. So when we're in
* lenient/compat mode, we have to deal with such broken POMs and mimic the way 2.x works.
*/
Map<String, Dependency> dependencies = new LinkedHashMap<String, Dependency>();
for ( Dependency dependency : model.getDependencies() )
{
dependencies.put( dependency.getManagementKey(), dependency );
}
model.setDependencies( new ArrayList<Dependency>( dependencies.values() ) );
dependencies.put( dependency.getManagementKey(), dependency );
}
model.setDependencies( new ArrayList<Dependency>( dependencies.values() ) );
}
private static class DuplicateMerger

View File

@ -377,13 +377,17 @@ public class DefaultModelValidator
boolean warning = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0;
String msg;
if ( String.valueOf( existing.getVersion() ).equals( dependency.getVersion() ) )
if ( StringUtils.isEmpty( existing.getVersion() ) && StringUtils.isEmpty( dependency.getVersion() ) )
{
msg = "duplicate declaration of " + dependency.getVersion();
msg = "duplicate declaration";
}
else if ( existing.getVersion().equals( dependency.getVersion() ) )
{
msg = "duplicate declaration of version " + dependency.getVersion();
}
else
{
msg = existing.getVersion() + " vs " + dependency.getVersion();
msg = "version " + existing.getVersion() + " vs " + dependency.getVersion();
}
addViolation( problems, warning, "'" + prefix