You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gustavo Morozowski <mo...@gmail.com> on 2015/08/06 20:01:51 UTC

find remote repository of artifact

Hi,

I am writing a maven plugin to resolve all project transitive dependencies
and reconstruct the URL of the remote repository of the resolved artifacts.

To resolve the dependencies I am injecting the ProjectDependenciesResolver,
and iterating over the result.getDependencyGraph().getChildren(). The
problem is, when I look at the DependencyNode.getRepositories(), it lists
all the configured remote repositories, and not the single remote
repository where it was resolved from. I tested this adding a dependency
that was avaliable in only a single repository.

There is also a file named "_remote.repositories" in the local maven
repository that tracks the remote repository where the artifact was
downloaded from, but I didn't find the api to query this metadata.

Is there some way to find this information?

Thanks,
Gustavo

-- sample code --

public class RemoteURLMojo extends AbstractMojo {
    @Parameter(defaultValue = "${project}", readonly = true, required =
true)
    private MavenProject project;
    @Parameter(defaultValue = "${repositorySystemSession}", readonly =
true, required = true)
    private RepositorySystemSession session;
    @Component
    private RepositorySystem system;
    @Component
    ProjectDependenciesResolver resolver;

    public void execute() throws MojoExecutionException,
MojoFailureException {

    DependencyResolutionRequest request = new
DefaultDependencyResolutionRequest(project, session);
    DependencyResolutionResult result;
    try {
        result = resolver.resolve(request);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }