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 397c925e8f..fdf3d8700c 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 @@ -138,6 +138,7 @@ public class DefaultModelValidator validateStringNotEmpty( "version", problems, false, model.getVersion() ); boolean warnOnBadBoolean = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; + boolean warnOnBadDependencyScope = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; for ( Dependency d : model.getDependencies() ) { @@ -177,6 +178,9 @@ public class DefaultModelValidator { validateBoolean( "dependencies.dependency.optional", problems, warnOnBadBoolean, d.getOptional(), d.getManagementKey() ); + + validateEnum( "dependencies.dependency.scope", problems, warnOnBadDependencyScope, d.getScope(), + d.getManagementKey(), "provided", "compile", "runtime", "test", "system" ); } } @@ -228,9 +232,6 @@ public class DefaultModelValidator boolean warnOnMissingPluginVersion = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1; - boolean warnOnBadPluginDependencyScope = - request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; - Build build = model.getBuild(); if ( build != null ) { @@ -252,7 +253,7 @@ public class DefaultModelValidator for ( Dependency d : p.getDependencies() ) { validateEnum( "build.plugins.plugin[" + p.getKey() + "].dependencies.dependency.scope", - problems, warnOnBadPluginDependencyScope, d.getScope(), d.getManagementKey(), + problems, warnOnBadDependencyScope, d.getScope(), d.getManagementKey(), "compile", "runtime", "system" ); } } 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 1baac7ab30..1adc4a853b 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 @@ -352,4 +352,16 @@ public class DefaultModelValidatorTest assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) ); } + public void testBadDependencyScope() + throws Exception + { + SimpleProblemCollector result = validate( "bad-dependency-scope.xml" ); + + assertViolations( result, 2, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:f" ) ); + + assertTrue( result.getErrors().get( 1 ).contains( "test:g" ) ); + } + } diff --git a/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml b/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml new file mode 100644 index 0000000000..0ae0b45ff6 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + aid + gid + 0.1 + + + + test + a + 0.2 + + + test + b + 0.2 + compile + + + test + c + 0.2 + runtime + + + test + d + 0.2 + test + + + test + e + 0.2 + provided + + + test + f + 0.2 + import + + + test + g + 0.2 + optional + + +