org.apache.maven.project.DefaultDependencyResolutionRequest Java Examples
The following examples show how to use
org.apache.maven.project.DefaultDependencyResolutionRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenGraphAdapter.java From depgraph-maven-plugin with Apache License 2.0 | 6 votes |
public void buildDependencyGraph(MavenProject project, ArtifactFilter globalFilter, GraphBuilder<DependencyNode> graphBuilder) { DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(); request.setMavenProject(project); request.setRepositorySession(getVerboseRepositorySession(project)); DependencyResolutionResult result; try { result = this.dependenciesResolver.resolve(request); } catch (DependencyResolutionException e) { throw new DependencyGraphException(e); } org.eclipse.aether.graph.DependencyNode root = result.getDependencyGraph(); ArtifactFilter transitiveDependencyFilter = createTransitiveDependencyFilter(project); GraphBuildingVisitor visitor = new GraphBuildingVisitor(graphBuilder, globalFilter, transitiveDependencyFilter, this.targetFilter, this.includedResolutions); root.accept(visitor); }
Example #2
Source File: MavenProjectConfigCollector.java From helidon-build-tools with Apache License 2.0 | 5 votes |
private List<String> dependencies(MavenProject project, MavenSession session) { try { return dependenciesResolver.resolve(new DefaultDependencyResolutionRequest(project, session.getRepositorySession()) .setResolutionFilter(DEPENDENCY_FILTER)) .getDependencies() .stream() .map(d -> d.getArtifact().getFile().toString()) .collect(Collectors.toList()); } catch (DependencyResolutionException e) { throw new RuntimeException("Dependency resolution failed: " + e.getMessage()); } }
Example #3
Source File: MutableMojo.java From java-specialagent with Apache License 2.0 | 5 votes |
private static DefaultDependencyResolutionRequest newDefaultDependencyResolutionRequest(final MavenSession session) { try { for (final Constructor<?> constructor : DefaultDependencyResolutionRequest.class.getConstructors()) if (constructor.getParameterTypes().length == 2 && constructor.getParameterTypes()[0] == MavenProject.class) return (DefaultDependencyResolutionRequest)constructor.newInstance(session.getCurrentProject(), getRepositorySystemSession(session)); return null; } catch (final IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new RuntimeException(e); } }
Example #4
Source File: UpdateStageDependenciesMojo.java From gitflow-helper-maven-plugin with Apache License 2.0 | 4 votes |
@Override protected void execute(final GitBranchInfo branchInfo) throws MojoExecutionException, MojoFailureException { getLog().debug("update-stage-dependencies setting up Repository session..."); DefaultRepositorySystemSession reresolveSession = new DefaultRepositorySystemSession(repositorySystemSession); reresolveSession.setUpdatePolicy(org.eclipse.aether.repository.RepositoryPolicy.UPDATE_POLICY_ALWAYS); reresolveSession.setCache(new DefaultRepositoryCache()); LocalRepositoryManager localRepositoryManager = reresolveSession.getLocalRepositoryManager(); getLog().debug("configuring stage as the remote repository for artifact resolution requests..."); List<RemoteRepository> stageRepo = Arrays.asList(RepositoryUtils.toRepo(getDeploymentRepository(stageDeploymentRepository))); boolean itemsPurged = false; try { DependencyResolutionResult depencencyResult = dependenciesResolver.resolve( new DefaultDependencyResolutionRequest(project, reresolveSession)); for (Dependency dependency : depencencyResult.getResolvedDependencies()) { if (!dependency.getArtifact().isSnapshot()) { // Find the artifact in the local repo, and if it came from the 'stageRepo', populate that info // as the 'repository' on the artifact. LocalArtifactResult localResult = localRepositoryManager.find(reresolveSession, new LocalArtifactRequest(dependency.getArtifact(), stageRepo, null)); // If the result has a file... and the getRepository() matched the stage repo id... if (localResult.getFile() != null && localResult.getRepository() != null) { getLog().info("Purging: " + dependency + " from remote repository: " + localResult.getRepository() + "."); File deleteTarget = new File(localRepositoryManager.getRepository().getBasedir(), localRepositoryManager.getPathForLocalArtifact(dependency.getArtifact())); if (deleteTarget.isDirectory()) { try { FileUtils.deleteDirectory(deleteTarget); } catch (IOException ioe) { getLog().warn("Failed to purge stage artifact from local repository: " + deleteTarget, ioe); } } else if (!deleteTarget.delete()) { getLog().warn("Failed to purge stage artifact from local repository: " + deleteTarget); } itemsPurged = true; } } } } catch (DependencyResolutionException dre) { throw new MojoExecutionException("Initial dependency resolution to resolve dependencies which may have been provided by the 'stage' repository failed.", dre); } if (itemsPurged) { try { getLog().info("Resolving purged dependencies..."); dependenciesResolver.resolve(new DefaultDependencyResolutionRequest(project, reresolveSession)); getLog().info("All stage dependencies purged and re-resolved."); } catch (DependencyResolutionException e) { throw new MojoExecutionException("Post-purge dependency resolution failed!", e); } } }