gnodet commented on PR #12745:
URL: https://github.com/apache/maven/pull/12745#issuecomment-6752500380

   _Claude Code on behalf of Guillaume Nodet_
   
   Hi Romain,
   
   Fair questions. Let me try to address them.
   
   **`api` duplicating `compile`**: Yes, behaviorally `api` is identical to 
`compile`. The value is in the paradigm shift: when a project adopts the new 
scopes, you'd use `api`/`implementation` exclusively (not mix them with 
`compile`). This makes the intent explicit — every dependency is a conscious 
choice about what you expose vs. what's internal. But you're right that `api` 
alone wouldn't justify the feature; `implementation` is the one that adds real 
value.
   
   Dropping `api` and keeping only `implementation` was considered, but 
`compile`/`implementation` as a pair is semantically incoherent — `compile` 
describes *when* a dependency is used, while `implementation` describes *who 
sees it*. The `api`/`implementation` pair gives a consistent vocabulary on the 
same axis: what's part of your public contract vs. what's an internal detail. 
This also maps well to the OSGi world: `api` dependencies correspond to 
exported packages, while `implementation` dependencies are the jars bundled 
inside the bundle but not exported.
   
   **`implementation` vs `provided`/`optional`**: They solve different 
problems. `provided` means "don't include this at runtime, something else will 
supply it" — but that's really a deployment concern, not a build-time one. 
What's "provided" in one deployment context isn't in another: the 
`maven-plugin-plugin` forces Maven jars to `provided` scope, which only works 
because you're deploying inside Maven. If Maven changes which jars it exposes 
(and it has, often), you have to adjust your scopes even though the library 
itself hasn't changed. `optional` means "consumers must opt-in explicitly," but 
it also removes the dep from the transitive runtime classpath entirely.
   
   `implementation` means something different from both: "this IS needed at 
runtime (it's bundled and transitive at runtime), but consumers shouldn't 
compile against it." None of the existing scopes express that.
   
   **Concrete example**: if library A uses Guava internally but doesn't expose 
Guava types in its API, today A declares Guava as `compile` and every consumer 
of A gets Guava on their compile classpath — even though they never use it 
directly. If A upgrades Guava, consumers that accidentally started depending on 
the transitive Guava can break. With `implementation`, A declares Guava as 
`implementation`: it's available to A at compile and runtime, available 
transitively to consumers at runtime (no `ClassNotFoundException`), but 
invisible to consumers at compile time. This is strictly better than `optional` 
(which removes it from runtime too) and different from `provided` (which is 
really about deployment context, not API visibility).


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