Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:49:56+00:00 2026-05-16T07:49:56+00:00

I’m trying to create a maven plugin to generate a file with the URL

  • 0

I’m trying to create a maven plugin to generate a file with the URL to all the dependencies in a project. I have been able to get the dependencies and their artifact, but I’m having trouble getting the download URL.

Using ArtifactResolver and ArtifactMetadataSource I get some of the artifact information. However I fail to get all the information for all the dependencies. I haven’t been able to find documentation on the resolution logic, so that I can call it form my plugin.
I can use an ArtifactResolver to download the artifact, but what I really wanted was just the URL.

The Maven Artifact API has a a method called getDownloadURL (see http://maven.apache.org/ref/2.0.4/maven-artifact/apidocs/org/apache/maven/artifact/Artifact.html). However I cant seem to find a way to get a real value into it. I always get a null value. Is there a way to have it resolved (downloading or not) and get the URL for where the file came from?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:49:57+00:00Added an answer on May 16, 2026 at 7:49 am

    I have to admit I have never written a Maven plugin before and saw your question as an good learning exercise. I borrowed heavily from the Maven Guide to Developing Java Plugins and the source code from the maven-dependency-plugin.

    I may be wrong about this but I do not think there is a direct mapping between artifact and repository that is stored anywhere by Maven.

    I have been a Maven user for sometime and you often see Maven querying every remote repository to ascertain the location of a given artifact. Therefore, in my code below you will not get a single URL for an artifact you will get as many URLs as there are remote repositories. You could always extend this code to attempt to download the artifact and retaining the URLs where the download is successful.

    I hope this helps.

    package sample.plugin;
    
    import java.util.List;
    import java.util.Set;
    import org.apache.maven.artifact.Artifact;
    import org.apache.maven.artifact.factory.ArtifactFactory;
    import org.apache.maven.artifact.repository.ArtifactRepository;
    import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
    import org.apache.maven.artifact.resolver.ArtifactResolutionException;
    import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
    import org.apache.maven.plugin.AbstractMojo;
    import org.apache.maven.plugin.MojoExecutionException;
    import org.apache.maven.project.MavenProject;
    import org.apache.maven.project.MavenProjectBuilder;
    import org.apache.maven.project.ProjectBuildingException;
    import org.apache.maven.project.artifact.InvalidDependencyVersionException;
    
    /**
     * Says "Hi" to the user.
     * @goal sayhi
     */
    public class GreetingMojo extends AbstractMojo {
    
        /**
         * @parameter expression="${localRepository}"
         * @readonly
         * @required
         */
        protected ArtifactRepository local;
        /**
         * @parameter expression="${project.remoteArtifactRepositories}"
         * @readonly
         * @required
         */
        protected List<ArtifactRepository> remoteRepos;
        /**
         * @component role="org.apache.maven.project.MavenProjectBuilder"
         * @required
         * @readonly
         */
        protected MavenProjectBuilder mavenProjectBuilder;
        /**
         * @component
         */
        protected ArtifactFactory factory;
        /**
         * @component
         */
        protected MavenProject project;
    
        public void execute() throws MojoExecutionException {
            try {
                resolveDependencies(project);
            } catch (Exception ex) {
                getLog().error(ex);
            }
        }
    
        private void resolveDependencies(MavenProject theProject)
                throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException, ProjectBuildingException {
            Set<Artifact> artifacts = theProject.createArtifacts(this.factory, Artifact.SCOPE_TEST,
                    new ScopeArtifactFilter(Artifact.SCOPE_TEST));
            for (Artifact a : artifacts) {
                System.out.printf("%s : %s : %s\n", a.getGroupId(), a.getArtifactId(), a.getVersion());
                for (ArtifactRepository r : remoteRepos) {
                    System.out.printf("%s/%s\n", r.getUrl(), r.pathOf(a));
                }
                System.out.println();
                Artifact pomArtifact = this.factory.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(), "", "pom");
                MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, remoteRepos, local);
                resolveDependencies(pomProject);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.