Improve dependency scope validation error messages for import scope #10991
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves Maven's dependency scope validation error messages to provide clearer guidance when the
import
scope is used incorrectly.Problem
Currently, when a user incorrectly uses
import
scope in a regular<dependencies>
section, Maven shows a confusing error message:This message is misleading because it suggests that
import
scope is never valid, when in fact it is valid in<dependencyManagement>
sections with<type>pom</type>
.Solution
The PR enhances the error message to provide context-aware guidance:
Key Improvements:
import
scope is validChanges Made
Core Changes
validateDependencyScope()
method in both implementations that provides context-aware error messagesimport
scope misuseFiles Modified
compat/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
compat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java
Additional Improvements
don't
→not
)Example Impact
This change helps users quickly understand how to fix their Maven configuration:
❌ Incorrect usage (triggers new helpful error):
✅ Correct usage:
Related Issues
Addresses the confusion reported in faktorips/faktorips.base#70
Testing
The validation logic remains unchanged - only the error messages are enhanced to be more helpful and educational.