Search in sources :

Example 11 with DependencyResolverException

use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.

the class DefaultDependencyResolver method updateDependencySetResolutionRequirements.

void updateDependencySetResolutionRequirements(final DependencySet set, final ResolutionManagementInfo requirements, AssemblyId assemblyId, ProjectBuildingRequest buildingRequest, final MavenProject... projects) throws DependencyResolutionException {
    requirements.setResolutionRequired(true);
    requirements.setResolvedTransitively(set.isUseTransitiveDependencies());
    ScopeFilter scopeFilter = FilterUtils.newScopeFilter(set.getScope());
    requirements.setScopeFilter(scopeFilter);
    for (final MavenProject project : projects) {
        if (project == null) {
            continue;
        }
        Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
        if (dependencyArtifacts == null) {
            try {
                ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(buildingRequest);
                pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
                Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(pbr, project.getModel(), scopeFilter);
                dependencyArtifacts = new HashSet<Artifact>();
                for (ArtifactResult artifactResult : artifactResults) {
                    dependencyArtifacts.add(artifactResult.getArtifact());
                }
                project.setDependencyArtifacts(dependencyArtifacts);
            } catch (final DependencyResolverException e) {
                throw new DependencyResolutionException("Failed to create dependency artifacts for resolution. Assembly: " + assemblyId, e);
            }
        }
        requirements.addArtifacts(dependencyArtifacts);
        getLogger().debug("Dependencies for project: " + project.getId() + " are:\n" + StringUtils.join(dependencyArtifacts.iterator(), "\n"));
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ScopeFilter(org.apache.maven.shared.artifact.filter.resolve.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Artifact(org.apache.maven.artifact.Artifact) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 12 with DependencyResolverException

use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.

the class GetMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("Skipping plugin execution");
        return;
    }
    if (coordinate.getArtifactId() == null && artifact == null) {
        throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
    }
    if (artifact != null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length < 3 || tokens.length > 5) {
            throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        coordinate.setGroupId(tokens[0]);
        coordinate.setArtifactId(tokens[1]);
        coordinate.setVersion(tokens[2]);
        if (tokens.length >= 4) {
            coordinate.setType(tokens[3]);
        }
        if (tokens.length == 5) {
            coordinate.setClassifier(tokens[4]);
        }
    }
    ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
    if (pomRemoteRepositories != null) {
        repoList.addAll(pomRemoteRepositories);
    }
    if (remoteRepositories != null) {
        // Use the same format as in the deploy plugin id::layout::url
        List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
        for (String repo : repos) {
            repoList.add(parseRepository(repo, always));
        }
    }
    try {
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(repoList);
        if (transitive) {
            getLog().info("Resolving " + coordinate + " with transitive dependencies");
            dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
        } else {
            getLog().info("Resolving " + coordinate);
            artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
        }
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    } catch (DependencyResolverException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 13 with DependencyResolverException

use of org.apache.maven.shared.dependencies.resolve.DependencyResolverException in project maven-plugins by apache.

the class AbstractJavadocMojo method getPathElements.

/**
 * Method that gets the classpath and modulepath elements that will be specified in the javadoc
 * <code>-classpath</code> and <code>--module-path</code> parameter.
 * Since we have all the sources of the current reactor, it is sufficient to consider the
 * dependencies of the reactor modules, excluding the module artifacts which may not yet be available
 * when the reactor project is built for the first time.
 *
 * @return all classpath elements
 * @throws MavenReportException if any.
 */
private List<File> getPathElements() throws MavenReportException {
    List<File> classpathElements = new ArrayList<>();
    Map<String, Artifact> compileArtifactMap = new HashMap<>();
    if (isTest()) {
        classpathElements.addAll(getProjectBuildOutputDirs(project));
    }
    populateCompileArtifactMap(compileArtifactMap, project.getArtifacts());
    if (isAggregator() && project.isExecutionRoot()) {
        List<String> reactorArtifacts = new ArrayList<>();
        for (MavenProject p : reactorProjects) {
            reactorArtifacts.add(p.getGroupId() + ':' + p.getArtifactId());
        }
        TransformableFilter dependencyFilter = new AndFilter(Arrays.asList(new PatternExclusionsFilter(reactorArtifacts), getDependencyScopeFilter()));
        for (MavenProject subProject : reactorProjects) {
            if (subProject != project) {
                classpathElements.addAll(getProjectBuildOutputDirs(subProject));
                try {
                    StringBuilder sb = new StringBuilder();
                    sb.append("Compiled artifacts for ");
                    sb.append(subProject.getGroupId()).append(":");
                    sb.append(subProject.getArtifactId()).append(":");
                    sb.append(subProject.getVersion()).append('\n');
                    ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest();
                    buildingRequest = buildingRequest.setRemoteRepositories(subProject.getRemoteArtifactRepositories());
                    for (ArtifactResult artifactResult : dependencyResolver.resolveDependencies(buildingRequest, subProject.getDependencies(), null, dependencyFilter)) {
                        populateCompileArtifactMap(compileArtifactMap, Collections.singletonList(artifactResult.getArtifact()));
                        sb.append(artifactResult.getArtifact().getFile()).append('\n');
                    }
                    if (getLog().isDebugEnabled()) {
                        getLog().debug(sb.toString());
                    }
                } catch (DependencyResolverException e) {
                    throw new MavenReportException(e.getMessage(), e);
                }
            }
        }
    }
    for (Artifact a : compileArtifactMap.values()) {
        classpathElements.add(a.getFile());
    }
    if (additionalDependencies != null) {
        for (Dependency dependency : additionalDependencies) {
            Artifact artifact = resolveDependency(dependency);
            getLog().debug("add additional artifact with path " + artifact.getFile());
            classpathElements.add(artifact.getFile());
        }
    }
    return classpathElements;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) PatternExclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter) Dependency(org.apache.maven.model.Dependency) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) AndFilter(org.apache.maven.shared.artifact.filter.resolve.AndFilter) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) TransformableFilter(org.apache.maven.shared.artifact.filter.resolve.TransformableFilter) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)13 Artifact (org.apache.maven.artifact.Artifact)9 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)9 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)8 ArrayList (java.util.ArrayList)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)5 DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)5 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)4 Dependency (org.apache.maven.model.Dependency)4 IOException (java.io.IOException)3 LinkedHashSet (java.util.LinkedHashSet)3 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)3 MavenProject (org.apache.maven.project.MavenProject)3 MavenReportException (org.apache.maven.reporting.MavenReportException)3 File (java.io.File)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2