-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[MNG-8099] Add explicit 'api' scope for dependencies and make 'compile' non-transitive for Maven 4 #12745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[MNG-8099] Add explicit 'api' scope for dependencies and make 'compile' non-transitive for Maven 4 #12745
Changes from all commits
421a3be
05d5d6b
d4722ec
bb369a8
1124211
3c8322e
feaf9e9
1caa5b9
b094c4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -582,8 +582,10 @@ private Model buildEffectiveModel(RepositorySystemSession session, MavenProject | |
| } | ||
| return dependency; | ||
| }); | ||
| // Only keep transitive scopes (null/empty => COMPILE) | ||
| // Only keep consumer-visible scopes (compile, api, runtime, implementation) | ||
| directDependencies.values().removeIf(DefaultConsumerPomBuilder::hasDependencyScope); | ||
| // Map 4.2.0 scopes to their 4.0.0 consumer POM equivalents (api→compile, implementation→runtime) | ||
| directDependencies.replaceAll((k, v) -> mapScopeForConsumerPom(v)); | ||
| managedDependencies.keySet().removeAll(directDependencies.keySet()); | ||
|
|
||
| model = model.withDependencyManagement( | ||
|
|
@@ -600,23 +602,45 @@ private Model buildEffectiveModel(RepositorySystemSession session, MavenProject | |
| Function.identity(), | ||
| this::merge, | ||
| LinkedHashMap::new)); | ||
| // Only keep transitive scopes | ||
| // Only keep consumer-visible scopes (compile, api, runtime, implementation) | ||
| directDependencies.values().removeIf(DefaultConsumerPomBuilder::hasDependencyScope); | ||
| // Map 4.2.0 scopes to their 4.0.0 consumer POM equivalents (api→compile, implementation→runtime) | ||
| directDependencies.replaceAll((k, v) -> mapScopeForConsumerPom(v)); | ||
| model = model.withDependencies(directDependencies.isEmpty() ? null : directDependencies.values()); | ||
| } | ||
|
|
||
| return model; | ||
| } | ||
|
|
||
| private static boolean hasDependencyScope(Dependency dependency) { | ||
| static boolean hasDependencyScope(Dependency dependency) { | ||
| String scopeId = dependency.getScope(); | ||
| DependencyScope scope; | ||
| if (scopeId == null || scopeId.isEmpty()) { | ||
| scope = DependencyScope.COMPILE; | ||
| } else { | ||
| scope = DependencyScope.forId(scopeId); | ||
| } | ||
| return scope == null || !scope.isTransitive(); | ||
| return scope != DependencyScope.COMPILE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The The method returns However, note that |
||
| && scope != DependencyScope.RUNTIME | ||
| && scope != DependencyScope.API | ||
| && scope != DependencyScope.IMPLEMENTATION; | ||
| } | ||
|
|
||
| /** | ||
| * Maps a 4.2.0 dependency scope to its 4.0.0 consumer POM equivalent. | ||
| * <ul> | ||
| * <li>{@code api} → {@code compile} (semantically identical, expresses intent)</li> | ||
| * <li>{@code implementation} → {@code runtime} (consumers cannot compile against it, present at runtime)</li> | ||
| * </ul> | ||
| */ | ||
| static Dependency mapScopeForConsumerPom(Dependency dependency) { | ||
| String scope = dependency.getScope(); | ||
| if (DependencyScope.API.id().equals(scope)) { | ||
| return dependency.withScope("compile"); | ||
| } else if (DependencyScope.IMPLEMENTATION.id().equals(scope)) { | ||
| return dependency.withScope("runtime"); | ||
| } | ||
| return dependency; | ||
| } | ||
|
|
||
| private Dependency merge(Dependency dep1, Dependency dep2) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Nit: consider positioning after RUNTIME
The new
APIandIMPLEMENTATIONenum constants are placed betweenCOMPILEandRUNTIME. This is defensible (grouping compile-related scopes together), but it changes the ordinal values ofRUNTIME,PROVIDED,TEST,TEST_ONLY,TEST_RUNTIME, andSYSTEM. SinceDependencyScopeis an@ExperimentalAPI this is technically fine — but worth noting that any code usingordinal()orvalues()ordering will see a change.Not blocking — just flagging for awareness.