gnodet-bot commented on code in PR #12745:
URL: https://github.com/apache/maven/pull/12745#discussion_r4274725078
##########
impl/maven-core/src/test/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilderTest.java:
##########
@@ -1499,4 +1499,110 @@ void
testHasNonModelPropertiesReturnsFalseForEnvAndSettingsProperties() {
DefaultConsumerPomBuilder.hasNonModelProperties("${env.HOME}-${ext.qualifier}",
Map.of()),
"Should return true when at least one property is not built-in
or in the model");
}
+
+ @Test
+ void testConsumerPomRetainsCompileApiRuntimeDeps() throws Exception {
+ // Consumer POMs must retain compile, api, and runtime dependencies
+ org.apache.maven.api.model.Dependency compileDep =
org.apache.maven.api.model.Dependency.newBuilder()
+ .groupId("g")
+ .artifactId("compile-dep")
+ .version("1")
+ .scope("compile")
+ .build();
+ org.apache.maven.api.model.Dependency apiDep =
org.apache.maven.api.model.Dependency.newBuilder()
+ .groupId("g")
+ .artifactId("api-dep")
+ .version("1")
+ .scope("api")
+ .build();
+ org.apache.maven.api.model.Dependency runtimeDep =
org.apache.maven.api.model.Dependency.newBuilder()
+ .groupId("g")
+ .artifactId("runtime-dep")
+ .version("1")
+ .scope("runtime")
+ .build();
+ org.apache.maven.api.model.Dependency unscopedDep =
org.apache.maven.api.model.Dependency.newBuilder()
+ .groupId("g")
+ .artifactId("unscoped-dep")
+ .version("1")
+ .build();
+
+ Model model = Model.newBuilder()
+ .groupId("test")
+ .artifactId("test")
+ .version("1.0")
+ .dependencies(List.of(compileDep, apiDep, runtimeDep,
unscopedDep))
+ .build();
+
+ Model transformed = DefaultConsumerPomBuilder.transformNonPom(model,
null);
+ assertNotNull(transformed.getDependencies());
+ // All four should be retained
+ assertTrue(
+ transformed.getDependencies().stream().anyMatch(d ->
"compile-dep".equals(d.getArtifactId())),
+ "compile-scoped dep should be retained");
+ assertTrue(
+ transformed.getDependencies().stream().anyMatch(d ->
"api-dep".equals(d.getArtifactId())),
+ "api-scoped dep should be retained");
Review Comment:
🟡 **Test gap: scope remapping not verified end-to-end**
This assertion checks that `api-dep` is retained, but not that its scope was
remapped to `"compile"` by `mapScopeForConsumerPom`. The unit-level
`testConsumerPomScopeMappings` covers the mapper in isolation, but this
integration test should also assert the mapped scope to catch any wiring bug
between the filter and mapper.
```suggestion
assertTrue(
transformed.getDependencies().stream().anyMatch(d ->
"api-dep".equals(d.getArtifactId())),
"api-scoped dep should be retained");
// Verify scope mapping: api -> compile in consumer POM
assertTrue(
transformed.getDependencies().stream()
.filter(d -> "api-dep".equals(d.getArtifactId()))
.allMatch(d -> "compile".equals(d.getScope())),
"api-scoped dep should be remapped to compile scope in
consumer POM");
```
--
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]