Skip to content

Commit e445b49

Browse files
gnodetclaude
andcommitted
[GH-11772] Fix CI failures: revert build POM resolution and fix consumer POM validation
- Revert DefaultModelBuilder.java build POM resolution change (can be a separate PR) to avoid side effects during parent resolution - Restore original mixin check in DefaultConsumerPomBuilder - Remove overly aggressive validation from flatten-enabled POM path that was rejecting mixin-containing POMs (model version 4.2.0) - Keep validation only on non-flatten path: consumer POMs that cannot be downgraded to 4.0.0 still fail fast with actionable guidance Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent edf1c47 commit e445b49

2 files changed

Lines changed: 29 additions & 58 deletions

File tree

impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ public Model build(RepositorySystemSession session, MavenProject project, ModelS
122122
// Check if this is a BOM (original packaging is "bom")
123123
boolean isBom = BOM_PACKAGING.equals(originalPackaging);
124124

125+
// Check if mixins are present without flattening enabled
126+
if (!model.getMixins().isEmpty() && !flattenEnabled && !model.isPreserveModelVersion()) {
127+
throw new MavenException("The consumer POM for "
128+
+ project.getId()
129+
+ " cannot be created because the POM contains mixins. "
130+
+ "Mixins are not supported in the default consumer POM format. "
131+
+ "You have the following options to resolve this:" + System.lineSeparator()
132+
+ " 1. Preserve the model version by setting 'preserve.model.version=true' to generate a consumer POM with <modelVersion>4.2.0</modelVersion>, which supports mixins"
133+
+ System.lineSeparator()
134+
+ " 2. Enable flattening by setting the property 'maven.consumer.pom.flatten=true' to remove mixins during transformation"
135+
+ System.lineSeparator()
136+
+ " 3. Remove the mixins from your POM");
137+
}
138+
125139
// Check if consumer POM flattening is disabled
126140
if (!flattenEnabled) {
127141
// When flattening is disabled, treat non-POM projects like parent POMs
@@ -133,8 +147,7 @@ public Model build(RepositorySystemSession session, MavenProject project, ModelS
133147
Model result = buildPom(session, project, src);
134148
// Validate: if flattening is disabled and the consumer POM cannot be downgraded
135149
// to 4.0.0, the consumer POM will contain features that Maven 3 / Gradle cannot
136-
// understand. Since enabling flattening would inline the parent and produce a
137-
// self-contained 4.0.0 POM, reject the build with actionable guidance.
150+
// understand. Reject the build with actionable guidance.
138151
if (!model.isPreserveModelVersion()
139152
&& !ModelBuilder.MODEL_VERSION_4_0_0.equals(result.getModelVersion())) {
140153
throw new MavenException("The consumer POM for " + project.getId()
@@ -159,22 +172,7 @@ public Model build(RepositorySystemSession session, MavenProject project, ModelS
159172
if (isBom) {
160173
return buildBom(session, project, src);
161174
} else {
162-
Model result = buildPom(session, project, src);
163-
// Validate: POM-packaged projects (parents) keep the parent reference
164-
// regardless of flatten setting. If the consumer POM cannot be downgraded
165-
// to 4.0.0, reject the build.
166-
if (!model.isPreserveModelVersion()
167-
&& !ModelBuilder.MODEL_VERSION_4_0_0.equals(result.getModelVersion())) {
168-
throw new MavenException("The consumer POM for " + project.getId()
169-
+ " cannot be downgraded to model version 4.0.0 because it contains"
170-
+ " features that require a newer model version." + System.lineSeparator()
171-
+ "You have the following options to resolve this:" + System.lineSeparator()
172-
+ " 1. Preserve the model version by setting 'preserve.model.version=true'"
173-
+ " on the <project> element (Maven 4 consumers only)"
174-
+ System.lineSeparator()
175-
+ " 2. Remove the features that require a newer model version");
176-
}
177-
return result;
175+
return buildPom(session, project, src);
178176
}
179177
} else {
180178
return buildNonPom(session, project, src);

impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,46 +1257,19 @@ Model resolveAndReadParentExternally(
12571257
? resolveReactorModel(groupId, artifactId, version)
12581258
: null;
12591259
if (modelSource == null) {
1260-
// For build requests resolving a regular parent (not mixin) from the repository,
1261-
// try the "build" classifier first to get the full-fidelity POM.
1262-
// The consumer POM (no classifier) may be stripped to 4.0.0 for backward
1263-
// compatibility, losing 4.1.0+ features that are needed during the build.
1264-
String resolveClassifier = classifier;
1265-
if (resolveClassifier == null && isBuildRequestWithActivation() && !(parent instanceof Mixin)) {
1266-
try {
1267-
ModelResolver.ModelResolverRequest buildReq = new ModelResolver.ModelResolverRequest(
1268-
request.getSession(),
1269-
null,
1270-
repositories,
1271-
groupId,
1272-
artifactId,
1273-
version,
1274-
"build",
1275-
"pom");
1276-
ModelResolver.ModelResolverResult buildResult = modelResolver.resolveModel(buildReq);
1277-
modelSource = buildResult.source();
1278-
if (buildResult.version() != null) {
1279-
parent = parent.withVersion(buildResult.version());
1280-
}
1281-
} catch (ModelResolverException e) {
1282-
// No build POM available, fall back to main POM
1283-
}
1284-
}
1285-
if (modelSource == null) {
1286-
ModelResolver.ModelResolverRequest req = new ModelResolver.ModelResolverRequest(
1287-
request.getSession(),
1288-
null,
1289-
repositories,
1290-
groupId,
1291-
artifactId,
1292-
version,
1293-
resolveClassifier,
1294-
extension != null ? extension : "pom");
1295-
ModelResolver.ModelResolverResult result = modelResolver.resolveModel(req);
1296-
modelSource = result.source();
1297-
if (result.version() != null) {
1298-
parent = parent.withVersion(result.version());
1299-
}
1260+
ModelResolver.ModelResolverRequest req = new ModelResolver.ModelResolverRequest(
1261+
request.getSession(),
1262+
null,
1263+
repositories,
1264+
groupId,
1265+
artifactId,
1266+
version,
1267+
classifier,
1268+
extension != null ? extension : "pom");
1269+
ModelResolver.ModelResolverResult result = modelResolver.resolveModel(req);
1270+
modelSource = result.source();
1271+
if (result.version() != null) {
1272+
parent = parent.withVersion(result.version());
13001273
}
13011274
}
13021275
} catch (ModelResolverException e) {

0 commit comments

Comments
 (0)