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"));
}
}
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);
}
}
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;
}
Aggregations