mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Read artifact descriptor before resolve
Call repositorySystem.readArtifactDescriptor before resolving launcher dependencies. This change allows remote snapshot dependencies that are not in the local repo to be downloaded. Issue: #52901751
This commit is contained in:
parent
7e579d3652
commit
618358287a
@ -41,6 +41,8 @@ import org.codehaus.plexus.archiver.zip.ZipResource;
|
|||||||
import org.sonatype.aether.RepositorySystem;
|
import org.sonatype.aether.RepositorySystem;
|
||||||
import org.sonatype.aether.RepositorySystemSession;
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
import org.sonatype.aether.repository.RemoteRepository;
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactDescriptorResult;
|
||||||
import org.sonatype.aether.resolution.ArtifactRequest;
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
import org.sonatype.aether.resolution.ArtifactResult;
|
import org.sonatype.aether.resolution.ArtifactResult;
|
||||||
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
@ -281,19 +283,29 @@ public abstract class AbstractExecutableArchiveMojo extends AbstractMojo {
|
|||||||
private ZipFile addLauncherClasses(MavenArchiver archiver)
|
private ZipFile addLauncherClasses(MavenArchiver archiver)
|
||||||
throws MojoExecutionException {
|
throws MojoExecutionException {
|
||||||
try {
|
try {
|
||||||
ArtifactRequest request = new ArtifactRequest();
|
|
||||||
String version = getClass().getPackage().getImplementationVersion();
|
|
||||||
request.setArtifact(new DefaultArtifact(
|
|
||||||
"org.springframework.bootstrap:spring-bootstrap-launcher:" + version));
|
|
||||||
List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();
|
List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();
|
||||||
repositories.addAll(this.project.getRemotePluginRepositories());
|
repositories.addAll(this.project.getRemotePluginRepositories());
|
||||||
repositories.addAll(this.project.getRemoteProjectRepositories());
|
repositories.addAll(this.project.getRemoteProjectRepositories());
|
||||||
ArtifactResult result = this.repositorySystem.resolveArtifact(
|
|
||||||
this.repositorySystemSession, request);
|
String version = getClass().getPackage().getImplementationVersion();
|
||||||
if (result.getArtifact() == null) {
|
DefaultArtifact artifact = new DefaultArtifact(
|
||||||
|
"org.springframework.bootstrap:spring-bootstrap-launcher:" + version);
|
||||||
|
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(
|
||||||
|
artifact, repositories, "plugin");
|
||||||
|
ArtifactDescriptorResult descriptorResult = this.repositorySystem
|
||||||
|
.readArtifactDescriptor(this.repositorySystemSession,
|
||||||
|
descriptorRequest);
|
||||||
|
|
||||||
|
ArtifactRequest artifactRequest = new ArtifactRequest();
|
||||||
|
artifactRequest.setRepositories(repositories);
|
||||||
|
artifactRequest.setArtifact(descriptorResult.getArtifact());
|
||||||
|
ArtifactResult artifactResult = this.repositorySystem.resolveArtifact(
|
||||||
|
this.repositorySystemSession, artifactRequest);
|
||||||
|
|
||||||
|
if (artifactResult.getArtifact() == null) {
|
||||||
throw new MojoExecutionException("Unable to resolve launcher classes");
|
throw new MojoExecutionException("Unable to resolve launcher classes");
|
||||||
}
|
}
|
||||||
return addLauncherClasses(archiver, result.getArtifact().getFile());
|
return addLauncherClasses(archiver, artifactResult.getArtifact().getFile());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (ex instanceof MojoExecutionException) {
|
if (ex instanceof MojoExecutionException) {
|
||||||
throw (MojoExecutionException) ex;
|
throw (MojoExecutionException) ex;
|
||||||
|
Loading…
Reference in New Issue
Block a user