Hello,
Actually, I developp a Maven plugin.
I need to resolve transitively dependencies which are not specified in the
POM of the plugin project.
So, I have written a function which look like to this :
public Set<Artifact> resolveTransitively(final String groupId, final String
artifactId,
final String version, final String
type,
final List<ArtifactRepository>
repositories)
throws Exception {
VersionRange vr = VersionRange.createFromVersionSpec(version);
Artifact artifact =
this.artifactFactory.createDependencyArtifact(groupId, artifactId, vr, type,
null, null);
ResolutionGroup resolutionGroup = metadataSource.retrieve(artifact,
this.localRepository, repositories);
repositories.addAll(resolutionGroup.getResolutionRepositories());
MavenProject prj = this.projectBuilder.buildFromRepository(artifact,
repositories, this.localRepository);
Set<Artifact> dependencies = resolutionGroup.getArtifacts();
dependencies.add(artifact);
ArtifactResolutionResult resolution =
this.artifactResolver.resolveTransitively(
dependencies,
prj.getArtifact(), Collections.EMPTY_MAP,
this.localRepository,
repositories,
this.metadataSource, null,
Collections.EMPTY_LIST);
Set<Artifact> result = resolution.getArtifacts();
if (result == null || result.isEmpty()) {
throw new ArtifactNotFoundException("Artifact not found.",
artifact);
}
return result;
}
It seems to the function works with artifacts of type: POM. For instance:
resolveTransitively("org.ow2.easybeans",
"easybeans-jpa-eclipselink-dependency", "1.1.0-RC2_JONAS", "pom",
project.getRemoteArtifactRepositories());
will produce the output:
Downloading:
http://repo1.maven.org/maven2/org/eclipse/persistence/eclipselink/1.0.1/eclipselink-1.0.1.pom
[INFO] Unable to find resource
'org.eclipse.persistence:eclipselink:pom:1.0.1' in repository central (
http://repo1.maven.org/maven2)
Downloading:
http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo/org/eclipse/persistence/eclipselink/1.0.1/eclipselink-1.0.1.pom
1K downloaded (eclipselink-1.0.1.pom)
Downloading:
http://repo1.maven.org/maven2/org/eclipse/persistence/eclipselink/1.0.1/eclipselink-1.0.1.jar
[INFO] Unable to find resource
'org.eclipse.persistence:eclipselink:jar:1.0.1' in repository central (
http://repo1.maven.org/maven2)
Downloading:
http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo/org/eclipse/persistence/eclipselink/1.0.1/eclipselink-1.0.1.jar
4395K downloaded (eclipselink-1.0.1.jar)
But, if I use the function on a JAR dependency:
resolveTransitivelyFiles("org.ow2.easybeans",
"easybeans-jpa-default-hibernate", "1.1.0-RC2_JONAS",
"jar", project.getRemoteArtifactRepositories());
The resulting set of artifacts is empty. So, the ArtifactNotFoundException
is thrown.
I have used the Maven API 2.1.0.
I have probably missed something, but I don't know why.
Thanks in advance for your help