From ce14c70fbd15ee2e9a82843231dec6132bd4a42f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 4 Aug 2023 12:00:08 +0100 Subject: [PATCH] Upgrade to Maven Resolver 1.9.14 Closes gh-36731 --- .../spring-boot-parent/build.gradle | 2 +- .../classpath/ModifiedClassPathClassLoader.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-parent/build.gradle b/spring-boot-project/spring-boot-parent/build.gradle index 17698c3d1da..7b9d4785c11 100644 --- a/spring-boot-project/spring-boot-parent/build.gradle +++ b/spring-boot-project/spring-boot-parent/build.gradle @@ -118,7 +118,7 @@ bom { ] } } - library("Maven Resolver", "1.6.3") { + library("Maven Resolver", "1.9.14") { group("org.apache.maven.resolver") { modules = [ "maven-resolver-api", diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java index b32890d790c..ce8b3155907 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java @@ -42,7 +42,6 @@ import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.impl.DefaultServiceLocator; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.resolution.ArtifactResult; @@ -230,11 +229,9 @@ final class ModifiedClassPathClassLoader extends URLClassLoader { private static List resolveCoordinates(String[] coordinates) { Exception latestFailure = null; - DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator(); - serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); - serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class); - RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class); + RepositorySystem repositorySystem = createRepositorySystem(); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + session.setSystemProperties(System.getProperties()); LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository"); RemoteRepository remoteRepository = new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2") @@ -260,6 +257,15 @@ final class ModifiedClassPathClassLoader extends URLClassLoader { latestFailure); } + @SuppressWarnings("deprecation") + private static RepositorySystem createRepositorySystem() { + org.eclipse.aether.impl.DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator(); + serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); + serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class); + RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class); + return repositorySystem; + } + private static List createDependencies(String[] allCoordinates) { List dependencies = new ArrayList<>(); for (String coordinate : allCoordinates) {