Search in sources :

Example 1 with MultipleArtifactsNotFoundException

use of org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveNonTransitively.

Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
    final List<Artifact> missing = new ArrayList<Artifact>();
    final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
    for (final Artifact depArtifact : dependencyArtifacts) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setLocalRepository(configSource.getLocalRepository());
        req.setRemoteRepositories(repos);
        req.setArtifact(depArtifact);
        ArtifactResolutionResult resolve = resolver.resolve(req);
        if (resolve.hasExceptions()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
            }
            missing.add(depArtifact);
        } else {
            resolved.add(depArtifact);
        }
    }
    if (!missing.isEmpty()) {
        final MavenProject project = configSource.getProject();
        final Artifact rootArtifact = project.getArtifact();
        final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
        throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
    }
    return resolved;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 MultipleArtifactsNotFoundException (org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException)1 MavenProject (org.apache.maven.project.MavenProject)1