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 f46be0edb9d5..a5b636f28f5b 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 @@ -467,6 +467,12 @@ else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) ) } else if ( "system".equals( dependency.getScope() ) ) { + + if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ) { + addViolation( problems, Severity.WARNING, Version.V31, prefix + ".scope", key, + "declares usage of deprecated 'system' scope ", dependency ); + } + String sysPath = dependency.getSystemPath(); if ( StringUtils.isNotEmpty( sysPath ) ) { 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 bb99be9a977e..4da3c878e553 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 @@ -418,7 +418,20 @@ public void testHardCodedSystemPath() assertViolations( result, 0, 0, 1 ); - assertTrue( result.getWarnings().get( 0 ).contains( "test:a:jar" ) ); + assertContains( result.getWarnings().get( 0 ), + "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" ); + + SimpleProblemCollector result_31 = validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ); + + assertViolations( result_31, 0, 0, 3 ); + + assertContains( result_31.getWarnings().get( 0 ), + "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" ); + assertContains( result_31.getWarnings().get( 1 ), + "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" ); + assertContains( result_31.getWarnings().get( 2 ), + "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" ); + } public void testEmptyModule() @@ -611,10 +624,23 @@ public void testSystemPathRefersToProjectBasedir() assertViolations( result, 0, 0, 2 ); - assertContains( result.getWarnings().get( 0 ), "'dependencies.dependency.systemPath' for test:a:jar " - + "should not point at files within the project directory" ); - assertContains( result.getWarnings().get( 1 ), "'dependencies.dependency.systemPath' for test:b:jar " - + "should not point at files within the project directory" ); + assertContains( result.getWarnings().get( 0 ), + "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" ); + assertContains( result.getWarnings().get( 1 ), + "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" ); + + SimpleProblemCollector result_31 = validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ); + + assertViolations( result_31, 0, 0, 4 ); + + assertContains( result_31.getWarnings().get( 0 ), + "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" ); + assertContains( result_31.getWarnings().get( 1 ), + "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" ); + assertContains( result_31.getWarnings().get( 2 ), + "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" ); + assertContains( result_31.getWarnings().get( 3 ), + "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" ); } public void testInvalidVersionInPluginManagement()