collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
private List<ArtifactResult> fetchArtifactWithDep(Dependency dep) throws DependencyResolutionException, ArtifactResolutionException { Artifact artifact = new DefaultArtifact(dep.getGroupArtifactVersion()); DependencyFilter classpathFilter = DependencyFilterUtils .classpathFilter(JavaScopes.COMPILE); PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter( dep.getExclusions()); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact, JavaScopes.COMPILE)); collectRequest.addRepository(mavenCentral); collectRequest.addRepository(mavenLocal); for (Repository repo : repositories) { RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl()); rr.setPolicy(repo.isSnapshot(), null); collectRequest.addRepository(rr); } DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter)); return system.resolveDependencies(session, dependencyRequest).getArtifactResults(); }
private static Dependency createDependency(final Artifact artifact) { final Dependency dependency = new Dependency(artifact, "runtime"); return dependency; }
/** * Sets the optional flag for the dependency. * * @param optional {@code true} if the dependency is optional, {@code false} if the dependency is mandatory. * @return The new dependency, never {@code null}. */ public Dependency setOptional( boolean optional ) { if ( this.optional == optional ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the optional flag for the dependency. * * @param optional {@code true} if the dependency is optional, {@code false} if the dependency is mandatory. * @return The new dependency, never {@code null}. */ public Dependency setOptional( boolean optional ) { if ( this.optional == optional ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the optional flag for the dependency. * * @param optional {@code true} if the dependency is optional, {@code false} if the dependency is mandatory. * @return The new dependency, never {@code null}. */ public Dependency setOptional( boolean optional ) { if ( this.optional == optional ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the artifact being depended on. * * @param artifact The artifact, must not be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setArtifact( Artifact artifact ) { if ( this.artifact.equals( artifact ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the artifact being depended on. * * @param artifact The artifact, must not be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setArtifact( Artifact artifact ) { if ( this.artifact.equals( artifact ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the artifact being depended on. * * @param artifact The artifact, must not be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setArtifact( Artifact artifact ) { if ( this.artifact.equals( artifact ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the scope of the dependency, e.g. "compile". * * @param scope The scope of the dependency, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setScope( String scope ) { if ( this.scope.equals( scope ) || ( scope == null && this.scope.length() <= 0 ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the scope of the dependency, e.g. "compile". * * @param scope The scope of the dependency, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setScope( String scope ) { if ( this.scope.equals( scope ) || ( scope == null && this.scope.length() <= 0 ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the scope of the dependency, e.g. "compile". * * @param scope The scope of the dependency, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setScope( String scope ) { if ( this.scope.equals( scope ) || ( scope == null && this.scope.length() <= 0 ) ) { return this; } return new Dependency( artifact, scope, exclusions, optional ); }
/** * Sets the exclusions for the dependency. * * @param exclusions The exclusions, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setExclusions( Collection<Exclusion> exclusions ) { if ( hasEquivalentExclusions( exclusions ) ) { return this; } return new Dependency( artifact, scope, optional, exclusions ); }
/** * Sets the exclusions for the dependency. * * @param exclusions The exclusions, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setExclusions( Collection<Exclusion> exclusions ) { if ( hasEquivalentExclusions( exclusions ) ) { return this; } return new Dependency( artifact, scope, optional, exclusions ); }
/** * Sets the exclusions for the dependency. * * @param exclusions The exclusions, may be {@code null}. * @return The new dependency, never {@code null}. */ public Dependency setExclusions( Collection<Exclusion> exclusions ) { if ( hasEquivalentExclusions( exclusions ) ) { return this; } return new Dependency( artifact, scope, optional, exclusions ); }
private Dependency toAetherDependency(org.apache.maven.model.Dependency dependency) { Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependency.getVersion()); ImmutableList.Builder<Exclusion> exclusions = ImmutableList.builder(); for (org.apache.maven.model.Exclusion exclusion : dependency.getExclusions()) { exclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), null, "*")); } return new Dependency(artifact, dependency.getScope(), dependency.isOptional(), exclusions.build()); }
public List<Artifact> resolveArtifacts(Iterable<? extends Artifact> sourceArtifacts) { CollectRequest collectRequest = new CollectRequest(); for (Artifact sourceArtifact : sourceArtifacts) { collectRequest.addDependency(new Dependency(sourceArtifact, JavaScopes.RUNTIME)); } for (RemoteRepository repository : repositories) { collectRequest.addRepository(repository); } DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME)); return resolveArtifacts(dependencyRequest); }
/** * Resolves dependencies transitively from the given jar artifact, with the specified Maven scope * (compile, runtime, and so on.) */ public DependencyResult resolveDependencies(GAV a, String scope) throws DependencyResolutionException { DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(scope); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(new DefaultArtifact(a.toString()), JavaScopes.COMPILE)); collectRequest.setRepositories(remoteRepositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter); return resolveDependencies(dependencyRequest); }
@Override public CollectorResult collectDependencies( ProjectBuildingRequest buildingRequest, DependableCoordinate root ) throws DependencyCollectorException { ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( root.getType() ); String extension = artifactHandler != null ? artifactHandler.getExtension() : null; Artifact aetherArtifact = new DefaultArtifact( root.getGroupId(), root.getArtifactId(), root.getClassifier(), extension, root.getVersion() ); CollectRequest request = new CollectRequest(); request.setRoot( new Dependency( aetherArtifact, null ) ); return collectDependencies( buildingRequest, request ); }
public DependencyTreeResult collectDependencies(String groupId, String artifactId, String version, String extension, String classifier) throws RepositoryException, ArtifactResolutionException, IOException, XmlPullParserException { Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, classifier, extension, version), "runtime"); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); List<RemoteRepository> repos = getRemoteRepositories(); for (RemoteRepository repo : repos) { collectRequest.addRepository(repo); } RepositorySystem repositorySystem = getRepositorySystem(); MavenRepositorySystemSession session = createRepositorSystemSession(offline, repositorySystem); DependencyNode rootNode = repositorySystem.collectDependencies(session, collectRequest).getRoot(); repositorySystem.resolveDependencies(session, rootNode, null); DependencyTreeResult result = new DependencyTreeResult(rootNode); return result; }