gnodet-bot commented on code in PR #13198:
URL: https://github.com/apache/maven/pull/13198#discussion_r4052340447
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java:
##########
@@ -1214,11 +1213,18 @@ void buildEffectiveModel(Collection<String> importIds)
throws ModelBuilderExcept
}
// effective model validation
- modelValidator.validateEffectiveModel(
- session,
- resultModel,
- isBuildRequest() ? ModelValidator.VALIDATION_LEVEL_STRICT
: ModelValidator.VALIDATION_LEVEL_MINIMAL,
- this);
+ // BUILD_PROJECT / BUILD_CONSUMER: full reactor context available
→ STRICT
+ // BUILD_EFFECTIVE: tooling-only, no reactor scan → MAVEN_2_0
(still catches structural
+ // errors, but version-managed-by-BOM does not become a fatal
cascade when reactor
+ // siblings are unresolvable; the root-cause error is already
reported by
+ // importDependencyManagement)
+ // everything else (CONSUMER_PARENT, CONSUMER_DEPENDENCY): MINIMAL
+ int effectiveValidationLevel = isBuildRequest()
+ ? ModelValidator.VALIDATION_LEVEL_STRICT
+ : isFilesystemRequest()
+ ? ModelValidator.VALIDATION_LEVEL_MAVEN_2_0
+ : ModelValidator.VALIDATION_LEVEL_MINIMAL;
+ modelValidator.validateEffectiveModel(session, resultModel,
effectiveValidationLevel, this);
Review Comment:
⚠️ **`VALIDATION_LEVEL_MAVEN_2_0` does not suppress
`validateDependencyVersion` — the fix doesn't work.**
The ternary here passes `MAVEN_2_0` to `validateEffectiveModel`, but
`validateDependencyVersion` inside `DefaultModelValidator` is called
unconditionally from `validateEffectiveDependency` — there is no
`validationLevel >= …` gate before it. It always emits `Severity.ERROR,
Version.BASE` for a dependency with a missing version. `hasErrors()` → `throw
newModelBuilderException()`. Same broken mechanism flagged in #13197.
The fix belongs in `DefaultModelValidator.validateDependencyVersion()`:
```suggestion
int effectiveValidationLevel = isBuildRequest()
? ModelValidator.VALIDATION_LEVEL_STRICT
: isFilesystemRequest()
? ModelValidator.VALIDATION_LEVEL_MAVEN_2_0
: ModelValidator.VALIDATION_LEVEL_MINIMAL;
modelValidator.validateEffectiveModel(session, resultModel,
effectiveValidationLevel, this);
```
…but `DefaultModelValidator.validateDependencyVersion` must also be updated
to respect `validationLevel`:
```java
// In DefaultModelValidator — demote to WARNING below STRICT
protected void validateDependencyVersion(ModelProblemCollector problems,
Dependency d, String prefix, int validationLevel) {
Severity severity = validationLevel >=
ModelValidator.VALIDATION_LEVEL_STRICT
? Severity.ERROR
: Severity.WARNING;
validateStringNotEmpty(prefix, "version", problems, severity,
Version.BASE, d.getVersion(),
SourceHint.dependencyManagementKey(d), d);
}
```
And all callers of `validateDependencyVersion` must pass `validationLevel`
through. Without that change, `BUILD_EFFECTIVE` still throws for BOM-managed
versions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]