ascheman commented on PR #11639:
URL: https://github.com/apache/maven/pull/11639#issuecomment-3864370320
I see an **issue with `preserve.model.version` handling:**
The current PR strips `<build>` and `<dependencies>` unconditionally for
modular projects, ignoring `preserveModelVersion`. This means even when a user
explicitly sets `preserve.model.version=true`, the modular elements are removed.
Suggested refactoring with integrated logic:
```java
static Model transformPom(Model model, MavenProject project) {
boolean preserveModelVersion = model.isPreserveModelVersion();
// raw to consumer transform
model = model.withRoot(false).withModules(null).withSubprojects(null);
if (model.getParent() != null) {
model = model.withParent(model.getParent().withRelativePath(null));
}
if (!preserveModelVersion) {
// Downgrade to 4.0.0 compatibility
if (isModular(project)) {
// <sources> element requires 4.1.0+, strip incompatible elements
model = model.withBuild(null);
model = model.withDependencies(null);
}
model = model.withPreserveModelVersion(false);
String modelVersion = new MavenModelVersion().getModelVersion(model);
model = model.withModelVersion(modelVersion);
}
// else: keep model as-is, including <build> and <dependencies> for
modular projects.
// Consumer POM will use model version 4.1.0+ if needed.
return model;
}
```
This way:
- `preserve.model.version=true` + modular → keep `<build>` and
`<dependencies>`, use 4.1.0+
- `preserve.model.version=false` (default) + modular → strip incompatible
elements, use 4.0.0
No new property needed - the existing `preserve.model.version` already
expresses the intent.
**Code suggestion:**
The `isModular()` method duplicates logic that already exists in
`SourceHandlingContext`. Consider extracting to a shared utility.
**Also:**
- Branch needs rebase (24 commits behind master)
- Unit tests for `isModular()` and `transformPom()` modular behavior would
help
--
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]