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


##########
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` incorrectly uses 
`nonTransitiveCompileDependencyScopes`.**
   
   `RS_MAIN_COMPILE_PLUS_RUNTIME` covers **both** compile and runtime build 
paths (`byProjectPath(PROJECT_PATH_MAIN)`). Using 
`nonTransitiveCompileDependencyScopes` (which includes `IMPLEMENTATION`) means 
transitive `implementation` deps get **eliminated** from the combined 
compile+runtime resolution — including the runtime portion. This violates the 
documented contract that `implementation` deps are "transitively available at 
runtime."
   
   Concrete failure: library A has `implementation` dep on lib B. Module C 
depends on A. Any plugin in C with `@requiresDependencyResolution = 
COMPILE_PLUS_RUNTIME` (surefire, maven-war-plugin, exec-maven-plugin, 
spring-boot:run) will NOT get B on its classpath → `ClassNotFoundException` at 
runtime in reactor builds.
   
   Only `RS_MAIN_COMPILE` and `RS_TEST_COMPILE` (pure compile scopes) should 
use `nonTransitiveCompileDependencyScopes`. Use the original 
`nonTransitiveDependencyScopes` here:
   
   ```suggestion
           result.add(internalScopeManager.createResolutionScope(
                   RS_MAIN_COMPILE_PLUS_RUNTIME,
                   InternalScopeManager.Mode.ELIMINATE,
                   byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
                   Collections.singletonList(system),
                   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`. 
The compat and impl copies must stay in sync.
   
   ```suggestion
           result.add(internalScopeManager.createResolutionScope(
                   RS_MAIN_COMPILE_PLUS_RUNTIME,
                   InternalScopeManager.Mode.ELIMINATE,
                   byProjectPath(CommonBuilds.PROJECT_PATH_MAIN),
                   Collections.singletonList(system),
                   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: that a consumer running against a library with an `implementation` 
dep can actually use that dep **at runtime**.
   
   This is the core invariant of the feature — without it, the 
`RS_MAIN_COMPILE_PLUS_RUNTIME` bug goes undetected because the consumer POM 
flattening masks it by converting `implementation` → `runtime` in published 
artifacts (but not in reactor builds where the POM has the original scopes).
   
   Add a test that runs the consumer (not just compiles it) using 
`exec-maven-plugin` or a main class, and verifies it runs without 
`ClassNotFoundException` even though it exercises a transitive `implementation` 
dep.



##########
api/maven-api-core/src/main/java/org/apache/maven/api/DependencyScope.java:
##########
@@ -93,7 +94,32 @@ public enum DependencyScope {
      * and test runtime classpaths, but not on the main compile or test 
compile classpaths.
      * Dependencies in this scope are transitive.
      */
-    RUNTIME("runtime", true),
+    RUNTIME("runtime"),
+
+    /**
+     * Api.

Review Comment:
   Nit: `Api.` should be `API.` — it's an acronym, same as `API` in the enum 
constant name.
   
   ```suggestion
        * API.
   ```



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