apache / apache/maven

[MNG-8099] Add explicit "api" scope for dependencies

Open
#10,786 0 comments 2 reactions 0 assignees View on GitHub
enhancement priority:major
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Henning Hoefer](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=hoeferh)** opened **[MNG-8099](https://issues.apache.org/jira/browse/MNG-8099?redirect=false)** and commented

(This is the suggestion that [melix](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=melix) made at the end of [Karl Heinz Marbaise](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=khmarbaise)'s recent [IDEA Conf talk on Maven 4](https://www.youtube.com/watch?v=tAGv4QH29QU). I couldn't find an existing issue for it, so I made this one – please link it if I missed a previously existing one.)

In Maven, `compile` scope dependencies by default are exported as transitive dependencies. This leads to developers relying on transitive dependencies in their code (often accidentally), then breakage when some depencies change, and overuse of `` trying to fix it.

Maven 4 with its new `modelVersion` gives us the chance for a better solution:

1. The `compile` scope should be changed to **not** transitively export dependencies.
2. A new scope named **`api`** should be added, signalling that dependencies with this scope become part of the modules API (and therefore become transitive dependencies for users of this module). This one essentially behaves like the `compile` scope before.

I believe that this will lead to smaller compile classpaths (faster and better code completion in IDEs, faster compilation), less fragile builds (less accidental reliance on transitive dependencies) and less dependency issues for developers overall. It also aligns nicely with how the Gradle Java plugin does it (`api`/`implementation`).

It will however break some builds which are relying on implicit transitive dependencies – and while that's kind of the point, it should only be done with the new `modelVersion` to opt into.

---

**Affects:** 4.0.0

1 votes, 2 watchers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.