From 8434aaeb13b4d04e7a54afd4dd99b54a85a1cbe9 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 20 Dec 2023 12:47:02 +0100 Subject: [PATCH 1/6] [MNG-7982] Make transitive the default depMgr Make the "transitive" depMgr the default in Maven4, while provide fallback to Maven3 used depMgr if needed. --- https://issues.apache.org/jira/browse/MNG-7982 --- ...DefaultRepositorySystemSessionFactory.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index a3e718f08b63..c190514f1ae9 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -66,6 +66,8 @@ import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.repository.WorkspaceReader; import org.eclipse.aether.resolution.ResolutionErrorPolicy; +import org.eclipse.aether.util.graph.manager.ClassicDependencyManager; +import org.eclipse.aether.util.graph.manager.TransitiveDependencyManager; import org.eclipse.aether.util.listener.ChainedRepositoryListener; import org.eclipse.aether.util.repository.AuthenticationBuilder; import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; @@ -102,6 +104,21 @@ public class DefaultRepositorySystemSessionFactory { */ private static final String MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE = "maven.repo.local.recordReverseTree"; + /** + * User property for selecting dependency manager implementation. Maven3 used "classic" only, that targeted full + * backward compatibility with Maven2: it ignores dependency management entries in transitive dependency POMs. + * Maven 4 by default uses "transitive" that unlike "classic", obeys dependency management entries deep in + * dependency graph as well. + * Default: {@code "transitive"}. Accepts values {@code "transitive"} and {@code "classic"}. + * + * @since 4.0.0 + */ + private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY = "maven.resolver.dependencyManager"; + + private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE = "transitive"; + + private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC = "classic"; + private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport"; private static final String MAVEN_RESOLVER_TRANSPORT_DEFAULT = "default"; @@ -392,6 +409,19 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) injectProxy(proxySelector, request.getPluginArtifactRepositories()); injectAuthentication(authSelector, request.getPluginArtifactRepositories()); + Object resolverDependencyManager = configProps.getOrDefault( + MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY, MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE); + if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE.equals(resolverDependencyManager)) { + session.setDependencyManager(new TransitiveDependencyManager()); + } else if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC.equals(resolverDependencyManager)) { + session.setDependencyManager(new ClassicDependencyManager()); + } else { + throw new IllegalArgumentException("Unknown resolver dependency manager '" + resolverDependencyManager + + "'. Supported managers are: " + + Arrays.asList( + MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE, MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC)); + } + ArrayList paths = new ArrayList<>(); paths.add(new File(request.getLocalRepository().getBasedir())); String localRepoTail = (String) configProps.get(MAVEN_REPO_LOCAL_TAIL); From 57679faef70cda0019fd9e0a0fa93018f52ce1b7 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 20 Dec 2023 13:48:24 +0100 Subject: [PATCH 2/6] Bring into game classicTransitive as well --- ...DefaultRepositorySystemSessionFactory.java | 22 +++++++++++++------ pom.xml | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index c190514f1ae9..8b34e0afd685 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -109,7 +109,9 @@ public class DefaultRepositorySystemSessionFactory { * backward compatibility with Maven2: it ignores dependency management entries in transitive dependency POMs. * Maven 4 by default uses "transitive" that unlike "classic", obeys dependency management entries deep in * dependency graph as well. - * Default: {@code "transitive"}. Accepts values {@code "transitive"} and {@code "classic"}. + *

+ * Default: {@code "classicTransitive"}. Accepts values {@code "classicTransitive"}, {@code "classic"} and + * {@code "transitive"}. * * @since 4.0.0 */ @@ -119,6 +121,8 @@ public class DefaultRepositorySystemSessionFactory { private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC = "classic"; + private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE = "classicTransitive"; + private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport"; private static final String MAVEN_RESOLVER_TRANSPORT_DEFAULT = "default"; @@ -410,16 +414,20 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) injectAuthentication(authSelector, request.getPluginArtifactRepositories()); Object resolverDependencyManager = configProps.getOrDefault( - MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY, MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE); - if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE.equals(resolverDependencyManager)) { - session.setDependencyManager(new TransitiveDependencyManager()); + MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY, MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE); + if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE.equals(resolverDependencyManager)) { + session.setDependencyManager(new ClassicDependencyManager(true)); } else if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC.equals(resolverDependencyManager)) { - session.setDependencyManager(new ClassicDependencyManager()); + session.setDependencyManager(new ClassicDependencyManager(false)); + } else if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE.equals(resolverDependencyManager)) { + session.setDependencyManager(new TransitiveDependencyManager()); } else { throw new IllegalArgumentException("Unknown resolver dependency manager '" + resolverDependencyManager - + "'. Supported managers are: " + + "'. Supported dependency managers are: " + Arrays.asList( - MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE, MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC)); + MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE, + MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC, + MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE)); } ArrayList paths = new ArrayList<>(); diff --git a/pom.xml b/pom.xml index eb32ccebcc74..a64fdd286457 100644 --- a/pom.xml +++ b/pom.xml @@ -176,7 +176,7 @@ under the License. 1.26 1.0.0 4.0.1 - 2.0.0-alpha-5 + 2.0.0-SNAPSHOT 2.0 0.9.0.M2 1.7.36 From 65a85cc876c54a02be50e838f872ff0b5f1c8d2d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 20 Dec 2023 15:45:19 +0100 Subject: [PATCH 3/6] Simplify It is really just about transitivity. The other two depMgrs are too "invasive". --- ...DefaultRepositorySystemSessionFactory.java | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index 8b34e0afd685..b77061093eae 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -67,7 +67,6 @@ import org.eclipse.aether.repository.WorkspaceReader; import org.eclipse.aether.resolution.ResolutionErrorPolicy; import org.eclipse.aether.util.graph.manager.ClassicDependencyManager; -import org.eclipse.aether.util.graph.manager.TransitiveDependencyManager; import org.eclipse.aether.util.listener.ChainedRepositoryListener; import org.eclipse.aether.util.repository.AuthenticationBuilder; import org.eclipse.aether.util.repository.ChainedLocalRepositoryManager; @@ -105,23 +104,17 @@ public class DefaultRepositorySystemSessionFactory { private static final String MAVEN_REPO_LOCAL_RECORD_REVERSE_TREE = "maven.repo.local.recordReverseTree"; /** - * User property for selecting dependency manager implementation. Maven3 used "classic" only, that targeted full - * backward compatibility with Maven2: it ignores dependency management entries in transitive dependency POMs. - * Maven 4 by default uses "transitive" that unlike "classic", obeys dependency management entries deep in - * dependency graph as well. + * User property for selecting dependency manager behaviour regarding transitive dependencies and dependency + * management entries in their POMs. Maven 3 targeted full backward compatibility with Maven2, hence it ignored + * dependency management entries in transitive dependency POMs. Maven 4 enables "transitivity" by default, hence + * unlike Maven2, obeys dependency management entries deep in dependency graph as well. *

- * Default: {@code "classicTransitive"}. Accepts values {@code "classicTransitive"}, {@code "classic"} and - * {@code "transitive"}. + * Default: {@code "true"}. * * @since 4.0.0 */ - private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY = "maven.resolver.dependencyManager"; - - private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE = "transitive"; - - private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC = "classic"; - - private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE = "classicTransitive"; + private static final String MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY_KEY = + "maven.resolver.dependencyManagerTransitivity"; private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport"; @@ -413,22 +406,10 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) injectProxy(proxySelector, request.getPluginArtifactRepositories()); injectAuthentication(authSelector, request.getPluginArtifactRepositories()); - Object resolverDependencyManager = configProps.getOrDefault( - MAVEN_RESOLVER_DEPENDENCY_MANAGER_KEY, MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE); - if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE.equals(resolverDependencyManager)) { - session.setDependencyManager(new ClassicDependencyManager(true)); - } else if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC.equals(resolverDependencyManager)) { - session.setDependencyManager(new ClassicDependencyManager(false)); - } else if (MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE.equals(resolverDependencyManager)) { - session.setDependencyManager(new TransitiveDependencyManager()); - } else { - throw new IllegalArgumentException("Unknown resolver dependency manager '" + resolverDependencyManager - + "'. Supported dependency managers are: " - + Arrays.asList( - MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC_TRANSITIVE, - MAVEN_RESOLVER_DEPENDENCY_MANAGER_CLASSIC, - MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVE)); - } + String resolverDependencyManagerTransitivity = (String) + configProps.getOrDefault(Boolean.TRUE.toString(), MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY_KEY); + session.setDependencyManager( + new ClassicDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity))); ArrayList paths = new ArrayList<>(); paths.add(new File(request.getLocalRepository().getBasedir())); From f9edd179693900acb9142c14cb74184ac2a67237 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 20 Dec 2023 15:46:46 +0100 Subject: [PATCH 4/6] Resolver configUtil vs map mixup --- .../internal/aether/DefaultRepositorySystemSessionFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index b77061093eae..ee241cdfa2e4 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -407,7 +407,7 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) injectAuthentication(authSelector, request.getPluginArtifactRepositories()); String resolverDependencyManagerTransitivity = (String) - configProps.getOrDefault(Boolean.TRUE.toString(), MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY_KEY); + configProps.getOrDefault(MAVEN_RESOLVER_DEPENDENCY_MANAGER_TRANSITIVITY_KEY, Boolean.TRUE.toString()); session.setDependencyManager( new ClassicDependencyManager(Boolean.parseBoolean(resolverDependencyManagerTransitivity))); From 0b0f18e35043057580f0c9e136d570630f187de0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Mon, 8 Jan 2024 12:48:23 +0100 Subject: [PATCH 5/6] Use staged resolver --- pom.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a3c1d0ff0323..74a359dc507e 100644 --- a/pom.xml +++ b/pom.xml @@ -177,7 +177,7 @@ under the License. 1.26 1.0.0 4.0.1 - 2.0.0-SNAPSHOT + 2.0.0-alpha-6 2.0 0.9.0.M2 1.7.36 @@ -508,6 +508,19 @@ under the License. + + + + true + + + false + + maven-2059 + https://repository.apache.org/content/repositories/maven-2059 + + + From ae60d45dc175faa83e348b63c811d60586c62dc0 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 11 Jan 2024 10:33:49 +0100 Subject: [PATCH 6/6] Use released --- pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pom.xml b/pom.xml index 74a359dc507e..45984bd6abd1 100644 --- a/pom.xml +++ b/pom.xml @@ -508,19 +508,6 @@ under the License. - - - - true - - - false - - maven-2059 - https://repository.apache.org/content/repositories/maven-2059 - - -