diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index ca89ce3b30..33b2f26139 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -356,11 +356,18 @@ public class DefaultModelValidator { String key = dependency.getManagementKey(); - if ( "pom".equals( dependency.getType() ) && "import".equals( dependency.getScope() ) - && StringUtils.isNotEmpty( dependency.getClassifier() ) ) + if ( "import".equals( dependency.getScope() ) ) { - addViolation( problems, errOn30, prefix + ".classifier", key, - "must be empty, imported POM cannot have a classifier.", dependency ); + if ( !"pom".equals( dependency.getType() ) ) + { + addViolation( problems, Severity.WARNING, prefix + ".type", key, + "must be 'pom' to import the managed dependencies.", dependency ); + } + else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) ) + { + addViolation( problems, errOn30, prefix + ".classifier", key, + "must be empty, imported POM cannot have a classifier.", dependency ); + } } else if ( "system".equals( dependency.getScope() ) ) { diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 0bbebfa55f..c93f0c305e 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -561,4 +561,26 @@ public class DefaultModelValidatorTest "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar is missing" ); } + public void testBadImportScopeType() + throws Exception + { + SimpleProblemCollector result = validateRaw( "bad-import-scope-type.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertContains( result.getWarnings().get( 0 ), + "'dependencyManagement.dependencies.dependency.type' for test:a:jar must be 'pom'" ); + } + + public void testBadImportScopeClassifier() + throws Exception + { + SimpleProblemCollector result = validateRaw( "bad-import-scope-classifier.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertContains( result.getErrors().get( 0 ), + "'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls must be empty" ); + } + } diff --git a/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-classifier.xml b/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-classifier.xml new file mode 100644 index 0000000000..833134511d --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-classifier.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + aid + gid + 0.1 + + + + + test + a + 0.1 + import + pom + cls + + + + diff --git a/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-type.xml b/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-type.xml new file mode 100644 index 0000000000..fb505c5429 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/bad-import-scope-type.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + aid + gid + 0.1 + + + + + test + a + 0.1 + import + + + + +