Cedric Beust created MRESOLVER-21:
-------------------------------------
Summary: Maven Resolver trying to resolve optional dependencies
Key: MRESOLVER-21
URL: https://issues.apache.org/jira/browse/MRESOLVER-21
Project: Maven Resolver
Issue Type: Bug
Components: resolver
Reporter: Cedric Beust
I modified the `ResolveTransitiveDependencies.java` example in two ways:
- Modified the id to `"org.springframework:spring-context-support:2.5.6.SEC03"`
- Replaced the filter with one that excludes optional dependencies
I'm including the full code below.
Despite that, `system.resolveDependencies()` fails with a
`DependencyResolutionException when trying to resolve a bunch of optional
dependencies, sugh as `jasperreports`.
```
public static void main( String[] args )
throws Exception
{
System.out.println(
"------------------------------------------------------------" );
System.out.println( ResolveTransitiveDependencies.class.getSimpleName()
);
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(
system );
Artifact artifact = new DefaultArtifact(
"org.springframework:spring-context-support:2.5.6.SEC03" );
DependencyFilter classpathFlter =
DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );
DependencyFilter optionalFilter = new DependencyFilter() {
@Override
public boolean accept(DependencyNode dependencyNode,
List<DependencyNode> list) {
return ! dependencyNode.getDependency().getOptional();
}
};
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE )
);
collectRequest.setRepositories( Booter.newRepositories( system, session
) );
DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest, optionalFilter );
try {
List<ArtifactResult> artifactResults =
system.resolveDependencies(session,
dependencyRequest).getArtifactResults();
for (ArtifactResult artifactResult : artifactResults) {
System.out.println(artifactResult.getArtifact() + " resolved to
"
+ artifactResult.getArtifact().getFile());
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
```
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)