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 369375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:54:49+00:00 2026-05-12T13:54:49+00:00

I have a Maven plugin that takes a groupId, artifactId, and version in its

  • 0

I have a Maven plugin that takes a groupId, artifactId, and version in its confiugration.

I want to be able to download that artifact from the remote repositories and copy the file into the project. I can’t figure out how to download the artifact though.

I understand that I can resolve dependencies using the dependency plugin, but I need it to happen inside my plugin. How can I do this?

  • 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-12T13:54:50+00:00Added an answer on May 12, 2026 at 1:54 pm

    Your plugin needs to create an Artifact using the ArtifactFactory and the groupId, artifactId and version of the artifact to be bootstrapped, then pass that artifact to an ArtifactResolver to handle the discovery/download.

    The resolver needs access to the local repository and remote repositories. The good news is that all those are plexus components that you can declare as dependencies in your Mojo and have Plexus wire them in for you.

    In another answer I showed how to do this. In your case you need a cut-down version with slightly different parameters to read the groupId, artifactId and version. In the plugin below, the various components are declared as plexus components, and the properties to declare the groupId, artifactId, version, and packaging type.

    package name.seller.rich.maven.plugins.bootstrap;
    
    import java.util.List;
    
    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.ArtifactResolver;
    import org.apache.maven.plugin.AbstractMojo;
    import org.apache.maven.plugin.MojoExecutionException;
    import org.apache.maven.plugin.MojoFailureException;
    
    /**
     * Obtain the artifact defined by the groupId, artifactId, and version
     * from the remote repository.
     * 
     * @goal bootstrap
     */
    public class BootstrapAppMojo extends AbstractMojo {
    
        /**
         * Used to look up Artifacts in the remote repository.
         * 
         * @parameter expression=
         *  "${component.org.apache.maven.artifact.factory.ArtifactFactory}"
         * @required
         * @readonly
         */
        protected ArtifactFactory factory;
    
        /**
         * Used to look up Artifacts in the remote repository.
         * 
         * @parameter expression=
         *  "${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
         * @required
         * @readonly
         */
        protected ArtifactResolver artifactResolver;
    
        /**
         * List of Remote Repositories used by the resolver
         * 
         * @parameter expression="${project.remoteArtifactRepositories}"
         * @readonly
         * @required
         */
        protected List remoteRepositories;
    
        /**
         * Location of the local repository.
         * 
         * @parameter expression="${localRepository}"
         * @readonly
         * @required
         */
        protected ArtifactRepository localRepository;
    
        /**
         * The target pom's artifactId
         * 
         * @parameter expression="${bootstrapArtifactId}"
         * @required
         */
        private String bootstrapArtifactId;
    
        /**
         * The target pom's groupId
         * 
         * @parameter expression="${bootstrapGroupId}"
         * @required
         */
        private String bootstrapGroupId;
    
        /**
         * The target pom's type
         * 
         * @parameter expression="${bootstrapType}"
         * @required
         */
        private String bootstrapType;
    
        /**
         * The target pom's version
         * 
         * @parameter expression="${bootstrapVersion}"
         * @required
         */
        private String bootstrapVersion;
    
        public void execute() throws MojoExecutionException, MojoFailureException {
            try {
                Artifact pomArtifact = this.factory.createArtifact(
                    bootstrapGroupId, bootstrapArtifactId, bootstrapVersion,
                    "", bootstrapType);
    
                artifactResolver.resolve(pomArtifact, this.remoteRepositories,
                    this.localRepository);
            } catch (ArtifactResolutionException e) {
                getLog().error("can't resolve parent pom", e);
            } catch (ArtifactNotFoundException e) {
                getLog().error("can't resolve parent pom", e);
            }
        }
    }
    

    This is an example of a pom configured to use the plugin (and download the aspectjrt 1.6.4 pom):

    <?xml version="1.0" encoding="UTF-8"?>
    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>name.seller.rich</groupId>
      <artifactId>bootstrap-test</artifactId>
      <version>1.0.0</version>
        <build>
          <plugins>
            <plugin>
              <groupId>name.seller.rich</groupId>
              <artifactId>maven-bootstrap-plugin</artifactId>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>bootstrap</goal>
                  </goals>
                  <configuration>
                    <bootstrapGroupId>org.aspectj</bootstrapGroupId>
                    <bootstrapArtifactId>aspectjrt</bootstrapArtifactId>
                    <bootstrapVersion>1.6.4</bootstrapVersion>
                    <bootstrapType>pom</bootstrapType>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
      </build>
    </project>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.