Skip to content

Commit 3ae65e0

Browse files
committed
Use Aether to download JUnit platform launcher
This commit updates our maven plugin to use aether directly, rather than the now deprecated maven features. Closes gh-36724
1 parent 9805723 commit 3ae65e0

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
9595
@Parameter(property = "spring-boot.aot.compilerArguments")
9696
private String compilerArguments;
9797

98+
protected final MavenSession getSession() {
99+
return this.session;
100+
}
101+
98102
@Override
99103
public void execute() throws MojoExecutionException, MojoFailureException {
100104
if (this.skip) {

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@
2626
import java.util.LinkedHashSet;
2727
import java.util.List;
2828
import java.util.Set;
29+
import java.util.stream.Collectors;
2930

31+
import org.apache.maven.RepositoryUtils;
3032
import org.apache.maven.artifact.Artifact;
3133
import org.apache.maven.artifact.DefaultArtifact;
3234
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
33-
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
34-
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
3535
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
3636
import org.apache.maven.plugin.MojoExecutionException;
3737
import org.apache.maven.plugins.annotations.Component;
3838
import org.apache.maven.plugins.annotations.LifecyclePhase;
3939
import org.apache.maven.plugins.annotations.Mojo;
4040
import org.apache.maven.plugins.annotations.Parameter;
4141
import org.apache.maven.plugins.annotations.ResolutionScope;
42-
import org.apache.maven.repository.RepositorySystem;
42+
import org.eclipse.aether.RepositorySystem;
43+
import org.eclipse.aether.collection.CollectRequest;
44+
import org.eclipse.aether.resolution.ArtifactResult;
45+
import org.eclipse.aether.resolution.DependencyRequest;
46+
import org.eclipse.aether.resolution.DependencyResult;
47+
import org.eclipse.aether.util.artifact.JavaScopes;
48+
import org.eclipse.aether.util.filter.DependencyFilterUtils;
4349

4450
/**
4551
* Invoke the AOT engine on tests.
@@ -97,20 +103,6 @@ public class ProcessTestAotMojo extends AbstractAotMojo {
97103
@Parameter(defaultValue = "${project.build.directory}/spring-aot/main/classes", required = true)
98104
private File generatedClasses;
99105

100-
/**
101-
* Local artifact repository used to resolve JUnit platform launcher jars.
102-
*/
103-
@SuppressWarnings("deprecation")
104-
@Parameter(defaultValue = "${localRepository}", required = true, readonly = true)
105-
private org.apache.maven.artifact.repository.ArtifactRepository localRepository;
106-
107-
/**
108-
* Remote artifact repositories used to resolve JUnit platform launcher jars.
109-
*/
110-
@SuppressWarnings("deprecation")
111-
@Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
112-
private List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories;
113-
114106
@Component
115107
private RepositorySystem repositorySystem;
116108

@@ -165,10 +157,10 @@ private URL[] addJUnitPlatformLauncher(URL[] classPath) throws Exception {
165157
String version = getJUnitPlatformVersion();
166158
DefaultArtifactHandler handler = new DefaultArtifactHandler("jar");
167159
handler.setIncludesDependencies(true);
168-
ArtifactResolutionResult resolutionResult = resolveArtifact(new DefaultArtifact(JUNIT_PLATFORM_GROUP_ID,
160+
Set<Artifact> artifacts = resolveArtifact(new DefaultArtifact(JUNIT_PLATFORM_GROUP_ID,
169161
JUNIT_PLATFORM_LAUNCHER_ARTIFACT_ID, version, null, "jar", null, handler));
170162
Set<URL> fullClassPath = new LinkedHashSet<>(Arrays.asList(classPath));
171-
for (Artifact artifact : resolutionResult.getArtifacts()) {
163+
for (Artifact artifact : artifacts) {
172164
fullClassPath.add(artifact.getFile().toURI().toURL());
173165
}
174166
return fullClassPath.toArray(URL[]::new);
@@ -185,16 +177,20 @@ private String getJUnitPlatformVersion() throws MojoExecutionException {
185177
return version;
186178
}
187179

188-
private ArtifactResolutionResult resolveArtifact(Artifact artifact) throws Exception {
189-
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
190-
request.setArtifact(artifact);
191-
request.setLocalRepository(this.localRepository);
192-
request.setResolveTransitively(true);
193-
request.setCollectionFilter(new RuntimeArtifactFilter());
194-
request.setRemoteRepositories(this.remoteRepositories);
195-
ArtifactResolutionResult result = this.repositorySystem.resolve(request);
196-
this.resolutionErrorHandler.throwErrors(request, result);
197-
return result;
180+
private Set<Artifact> resolveArtifact(Artifact artifact) throws Exception {
181+
CollectRequest collectRequest = new CollectRequest();
182+
collectRequest.setRoot(RepositoryUtils.toDependency(artifact, null));
183+
collectRequest.setRepositories(this.project.getRemotePluginRepositories());
184+
DependencyRequest request = new DependencyRequest();
185+
request.setCollectRequest(collectRequest);
186+
request.setFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
187+
DependencyResult dependencyResult = this.repositorySystem
188+
.resolveDependencies(getSession().getRepositorySession(), request);
189+
return dependencyResult.getArtifactResults()
190+
.stream()
191+
.map(ArtifactResult::getArtifact)
192+
.map(RepositoryUtils::toArtifact)
193+
.collect(Collectors.toSet());
198194
}
199195

200196
}

0 commit comments

Comments
 (0)