Repository navigation
Improve dependency scope validation error messages for import scope - #10991
Merged
gnodet merged 1 commit intoSep 3, 2025
Merged
Conversation
elharo
reviewed
Jul 23, 2025
gnodet
force-pushed
the
improve-dependency-scope-validation-messages
branch
from
July 23, 2025 10:20
c8519ab to
5d2db36
Compare
- Enhance error message when 'import' scope is used incorrectly in regular dependencies - Provide clear guidance that 'import' scope is only valid in <dependencyManagement> sections - Replace generic error message with context-aware validation - Update both Maven 3 (compat) and Maven 4 (impl) implementations for consistency - Update tests to verify the improved error messages - Fix grammar in comments (don't -> not) - Apply spotless formatting Before: 'dependencies.dependency.scope' must be one of [provided, compile, runtime, test, system] but is 'import'. After: 'dependencies.dependency.scope' has scope 'import'. The 'import' scope is only valid in <dependencyManagement> sections. This addresses the confusion reported in faktorips/faktorips.base#70 where users receive misleading error messages that suggest 'import' scope is never valid, when it's actually valid in dependency management sections with type=pom.
gnodet
force-pushed
the
improve-dependency-scope-validation-messages
branch
from
July 23, 2025 14:12
6c749dc to
3647fe8
Compare
elharo
approved these changes
Jul 26, 2025
Member
|
The deprecated code and impl code is diverging (like new maven4 scopes cannot be validated with deprecated code). If this is not a concern, am ok. |
2 of 3 tasks
gnodet
added a commit
to gnodet/maven
that referenced
this pull request
May 19, 2026
…pache#10991) - Enhance error message when 'import' scope is used incorrectly in regular dependencies - Provide clear guidance that 'import' scope is only valid in <dependencyManagement> sections - Replace generic error message with context-aware validation - Update both Maven 3 (compat) and Maven 4 (impl) implementations for consistency - Update tests to verify the improved error messages - Fix grammar in comments (don't -> not) - Apply spotless formatting Before: 'dependencies.dependency.scope' must be one of [provided, compile, runtime, test, system] but is 'import'. After: 'dependencies.dependency.scope' has scope 'import'. The 'import' scope is only valid in <dependencyManagement> sections. This addresses the confusion reported in faktorips/faktorips.base#70 where users receive misleading error messages that suggest 'import' scope is never valid, when it's actually valid in dependency management sections with type=pom.
gnodet
added a commit
that referenced
this pull request
May 19, 2026
* Add Maven version to error message when rejecting model versions (#10921) Port #10899 to master, using Session.getMavenVersion() instead of reading properties file. - Modified validateModelVersion() to accept Session parameter and include Maven version in error messages - Updated error messages to be single-line and consistent with Maven's style - Enhanced error messages show which Maven version is rejecting the model version - Added test coverage to verify Maven version is included in error messages This helps users (especially IDE users like NetBeans) understand version compatibility issues more clearly. * Improve ProjectBuildingException error messages with detailed problem reporting (#10975) * Refactor ProjectBuildingException constructors for improved clarity * Add unit tests for ProjectBuildingException message generation * Refactor ProjectBuildingException for improved clarity and maintainability * Add unit tests for ProjectBuildingException to enhance message validation * style: Apply Spotless formatting * Refactor createMessage method to improve error counting logic in ProjectBuildingException * Refactor ProjectBuildingException for improved clarity and maintainability * Refactor createMessage method to streamline error message formattingRefactor createMessage method to streamline error message formatting * Refactor:Spotless formating * Improve dependency scope validation error messages for import scope (#10991) - Enhance error message when 'import' scope is used incorrectly in regular dependencies - Provide clear guidance that 'import' scope is only valid in <dependencyManagement> sections - Replace generic error message with context-aware validation - Update both Maven 3 (compat) and Maven 4 (impl) implementations for consistency - Update tests to verify the improved error messages - Fix grammar in comments (don't -> not) - Apply spotless formatting Before: 'dependencies.dependency.scope' must be one of [provided, compile, runtime, test, system] but is 'import'. After: 'dependencies.dependency.scope' has scope 'import'. The 'import' scope is only valid in <dependencyManagement> sections. This addresses the confusion reported in faktorips/faktorips.base#70 where users receive misleading error messages that suggest 'import' scope is never valid, when it's actually valid in dependency management sections with type=pom. * Fixes #10950: Throw ProjectBuildingException for reactor cycles; keep CycleDetectedException as cause. (#11091) Non-cycle model problems still use ProjectBuildingException(results). Remove misleading comment about projectId/pomFile. * Fix NullPointerException when clearing project properties Fix #11552 --------- Co-authored-by: Pasan Kavinda Abeysekara <69195287+PasanAbeysekara@users.noreply.github.com> Co-authored-by: Arturo Bernal <abernal@apache.org> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
importscope is used incorrectly.Problem
Currently, when a user incorrectly uses
importscope in a regular<dependencies>section, Maven shows a confusing error message:This message is misleading because it suggests that
importscope 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:
importscope is validChanges Made
Core Changes
validateDependencyScope()method in both implementations that provides context-aware error messagesimportscope misuseFiles Modified
compat/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.javacompat/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.javaimpl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.javaimpl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.javaAdditional 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.