gnodet-bot commented on code in PR #12745:
URL: https://github.com/apache/maven/pull/12745#discussion_r4600254201


##########
impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/scopes/Maven4ScopeManagerConfiguration.java:
##########
@@ -155,13 +162,13 @@ public 
Collection<org.eclipse.aether.scope.ResolutionScope> buildResolutionScope
                 InternalScopeManager.Mode.ELIMINATE,
                 singleton(CommonBuilds.PROJECT_PATH_MAIN, 
CommonBuilds.BUILD_PATH_COMPILE),
                 Collections.singletonList(system),
-                nonTransitiveDependencyScopes));
+                nonTransitiveCompileDependencyScopes));
         result.add(internalScopeManager.createResolutionScope(
                 RS_MAIN_COMPILE_PLUS_RUNTIME,
                 InternalScopeManager.Mode.ELIMINATE,
                 byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
                 Collections.singletonList(system),
-                nonTransitiveDependencyScopes));
+                nonTransitiveCompileDependencyScopes));

Review Comment:
   ⚠️ **Bug: `RS_MAIN_COMPILE_PLUS_RUNTIME` must use 
`nonTransitiveDependencyScopes`, not `nonTransitiveCompileDependencyScopes`.** 
   
   `nonTransitiveCompileDependencyScopes` includes `implementation`, which 
eliminates transitive implementation deps from this resolution scope. 
`RS_MAIN_COMPILE_PLUS_RUNTIME` is used by surefire, exec-maven-plugin, and 
other plugins for COMPILE_PLUS_RUNTIME resolution — they need 
runtime-transitive implementation deps on the classpath. Tests will silently 
get `NoClassDefFoundError` for transitive classes that should be there.
   
   `RS_MAIN_COMPILE` correctly uses `nonTransitiveCompileDependencyScopes` 
(compile-only, right). This scope covers runtime too — use 
`nonTransitiveDependencyScopes` here.
   
   ```suggestion
                   nonTransitiveDependencyScopes));
   ```



##########
compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/scopes/Maven4ScopeManagerConfiguration.java:
##########
@@ -157,13 +164,13 @@ public 
Collection<org.eclipse.aether.scope.ResolutionScope> buildResolutionScope
                 InternalScopeManager.Mode.ELIMINATE,
                 singleton(CommonBuilds.PROJECT_PATH_MAIN, 
CommonBuilds.BUILD_PATH_COMPILE),
                 Collections.singletonList(system),
-                nonTransitiveDependencyScopes));
+                nonTransitiveCompileDependencyScopes));
         result.add(internalScopeManager.createResolutionScope(
                 RS_MAIN_COMPILE_PLUS_RUNTIME,
                 InternalScopeManager.Mode.ELIMINATE,
                 byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
                 Collections.singletonList(system),
-                nonTransitiveDependencyScopes));
+                nonTransitiveCompileDependencyScopes));

Review Comment:
   ⚠️ **Same bug as the impl copy:** `RS_MAIN_COMPILE_PLUS_RUNTIME` must use 
`nonTransitiveDependencyScopes`, not `nonTransitiveCompileDependencyScopes`.
   
   ```suggestion
                   nonTransitiveDependencyScopes));
   ```



##########
its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8099ApiImplementationScopesTest.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Integration test for api and implementation dependency scopes (MNG-8099).
+ *
+ * Verifies that:
+ * - api-scoped deps are transitively visible to consumers at compile time
+ * - implementation-scoped deps are NOT transitively visible at compile time
+ *
+ * The test installs a library that uses both api and implementation scopes,
+ * then builds two standalone consumers:
+ * - consumer: directly uses ApiDep (transitive via api) — should compile
+ * - consumer-impl-fail: directly uses ImplDep (transitive via implementation) 
— should fail
+ */
+public class MavenITmng8099ApiImplementationScopesTest extends 
AbstractMavenIntegrationTestCase {
+
+    @BeforeEach
+    void installDependencies() throws Exception {
+        Path testDir = extractResources("mng-8099-api-implementation-scopes");
+
+        Verifier verifier = newVerifier(testDir, false);
+        verifier.addCliArgument("install");
+        verifier.addCliArgument("-Dmaven.consumer.pom.flatten=true");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+    }
+
+    /**
+     * Consumer directly references ApiDep (transitive via api scope from 
library).
+     * Should compile successfully because api deps are transitive at compile 
time.
+     */
+    @Test
+    public void testApiScopeIsTransitiveAtCompileTime() throws Exception {
+        Path testDir = extractResources("mng-8099-api-implementation-scopes");
+        Path consumerDir = testDir.resolve("consumer");
+
+        Verifier verifier = newVerifier(consumerDir.toString(), false);
+        verifier.addCliArgument("clean");
+        verifier.addCliArgument("compile");
+        verifier.addCliArgument("-Dmaven.consumer.pom.flatten=true");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+    }
+
+    /**
+     * Consumer directly references ImplDep (transitive via implementation 
scope from library).
+     * Should FAIL to compile because implementation deps are NOT transitive 
at compile time.
+     */
+    @Test
+    public void testImplementationScopeIsNotTransitiveAtCompileTime() throws 
Exception {
+        Path testDir = extractResources("mng-8099-api-implementation-scopes");
+        Path consumerDir = testDir.resolve("consumer-impl-fail");
+
+        Verifier verifier = newVerifier(consumerDir.toString(), false);
+        verifier.addCliArgument("clean");
+        verifier.addCliArgument("compile");
+        verifier.addCliArgument("-Dmaven.consumer.pom.flatten=true");
+
+        assertThrows(
+                VerificationException.class,
+                verifier::execute,
+                "Compilation should fail because ImplDep is not transitively 
visible at compile time");
+    }
+}

Review Comment:
   **Missing runtime-transitivity test.** The IT only verifies the negative 
case (implementation deps not visible at compile time). It never verifies the 
positive case: that a consumer can actually *run* against a transitive 
implementation dep. This is the most important invariant — it's what guarantees 
no `NoClassDefFoundError` at runtime. Add a test that installs the library, 
then runs a consumer that invokes `ImplDep` at runtime (e.g. via reflection or 
a main class) and verifies the build succeeds.



-- 
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]

Reply via email to