use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method reResolveArtifacts.
private void reResolveArtifacts(MavenProject theProject, Set<Artifact> artifacts, ArtifactFilter filter) throws ArtifactResolutionException, ArtifactNotFoundException {
// because Maven 2 will not automatically re-resolve them when resolving the artifact
for (Artifact artifact : artifacts) {
try {
// CHECKSTYLE_OFF: LineLength
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), org.apache.maven.shared.artifact.TransferUtils.toArtifactCoordinate(artifact));
// CHECKSTYLE_ON: LineLength
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
}
}
List<Artifact> missingArtifacts = new ArrayList<Artifact>();
for (Artifact artifact : artifacts) {
verbose("Resolving artifact: " + artifact.getId());
try {
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
missingArtifacts.add(artifact);
}
}
if (missingArtifacts.size() > 0) {
StringBuffer message = new StringBuffer("required artifacts missing:\n");
for (Artifact missingArtifact : missingArtifacts) {
message.append(" ").append(missingArtifact.getId()).append('\n');
}
message.append("\nfor the artifact:");
throw new ArtifactResolutionException(message.toString(), theProject.getArtifact(), theProject.getRemoteArtifactRepositories());
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method purgeLocalRepository.
/**
* Purges the local repository for the dependencies in the given Maven project.
*
* @param theProject Maven project.
* @param resolvedArtifactsToPurge The artifacts that were already purged.
* @throws MojoFailureException in case of errors during the purge.
*/
private void purgeLocalRepository(MavenProject theProject, Set<Artifact> purgedArtifacts) throws MojoFailureException {
List<Dependency> dependencies = theProject.getDependencies();
TransformableFilter dependencyFilter = createPurgeArtifactsFilter(theProject, dependencies, purgedArtifacts);
Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(theProject, dependencies, dependencyFilter);
if (resolvedArtifactsToPurge.isEmpty()) {
getLog().info("No artifacts included for purge for project: " + theProject.getId());
return;
}
verbose("Purging dependencies for project: " + theProject.getId());
purgeArtifacts(resolvedArtifactsToPurge);
purgedArtifacts.addAll(resolvedArtifactsToPurge);
if (reResolve) {
ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
try {
reResolveArtifacts(theProject, resolvedArtifactsToPurge, artifactFilter);
} catch (ArtifactResolutionException e) {
String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
} catch (ArtifactNotFoundException e) {
String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
}
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project m2e-nar by maven-nar.
the class AbstractDependencyMojo method downloadAttachedNars.
@SuppressWarnings("deprecation")
public final void downloadAttachedNars(final List<AttachedNarArtifact> dependencies) throws MojoExecutionException, MojoFailureException {
getLog().debug("Download for NarDependencies {");
for (final AttachedNarArtifact attachedNarArtifact : dependencies) {
getLog().debug(" - " + attachedNarArtifact);
}
getLog().debug("}");
for (final AttachedNarArtifact attachedNarArtifact : dependencies) {
try {
getLog().debug("Resolving " + attachedNarArtifact);
this.artifactResolver.resolve(attachedNarArtifact, this.remoteArtifactRepositories, getLocalRepository());
} catch (final ArtifactNotFoundException e) {
final String message = "nar not found " + attachedNarArtifact.getId();
throw new MojoExecutionException(message, e);
} catch (final ArtifactResolutionException e) {
final String message = "nar cannot resolve " + attachedNarArtifact.getId();
throw new MojoExecutionException(message, e);
}
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project tomee by apache.
the class AbstractTomEEMojo method getAdditionalClasspath.
/**
* Gets additional classpath.
*
* @return the additional classpath
*/
protected String getAdditionalClasspath() {
if (!classpaths.isEmpty()) {
final StringBuilder cpBuilder = new StringBuilder();
for (final String cp : classpaths) {
final String[] split = cp.split(":");
if (split.length >= 3) /*GAV*/
{
final FileWithMavenMeta jar;
try {
jar = resolve(split[0], split[1], split[2], split.length > 4 ? split[4] : null, split.length > 3 ? split[3] : "jar");
} catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
throw new IllegalArgumentException(e);
}
final File classpathRoot = new File(catalinaBase, "boot");
if (!classpathRoot.isDirectory()) {
mkdirs(classpathRoot);
}
final File target = new File(classpathRoot, stripVersion ? jar.stripVersion(true) : jar.resolved.getName());
try {
IO.copy(jar.resolved, target);
} catch (final IOException e) {
throw new IllegalArgumentException(e);
}
cpBuilder.append("${openejb.base}/boot/").append(target.getName());
} else {
// else plain path
cpBuilder.append(cp);
}
if (classpathSeparator == null) {
classpathSeparator = File.pathSeparator;
}
cpBuilder.append(classpathSeparator);
}
// Dump the final path separator
return cpBuilder.substring(0, cpBuilder.length() - 1);
}
return null;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project tycho by eclipse.
the class TychoOsgiRuntimeLocator method resolveDependency.
public Artifact resolveDependency(MavenSession session, Dependency dependency) throws MavenExecutionException {
Artifact artifact = repositorySystem.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getType());
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
request.setRemoteRepositories(getPluginRepositories(session));
request.setCache(session.getRepositoryCache());
request.setOffline(session.isOffline());
request.setProxies(session.getSettings().getProxies());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
try {
resolutionErrorHandler.throwErrors(request, result);
} catch (ArtifactResolutionException e) {
throw new MavenExecutionException("Could not resolve artifact for Tycho's OSGi runtime", e);
}
return artifact;
}
Aggregations