mirror of https://github.com/apache/maven.git
[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:
parent
61ba8778b6
commit
c980cfb28d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue