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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:30+00:00 2026-05-26T06:26:30+00:00

How do I programmatically construct a MavenProject instance (not the current project) given its

  • 0

How do I programmatically construct a MavenProject instance (not the current project) given its groupId, artifactId, version, etc?

UPDATE: I’m trying to create a patch for http://jira.codehaus.org/browse/MDEP-322. I believe the maven-dependency-plugin depends on Maven 2.x so I can’t use any Maven 3.x APIs.

  • 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-26T06:26:31+00:00Added an answer on May 26, 2026 at 6:26 am

    How you would go about doing this depends on whether you want to construct the project from an artifact in your local repository or from a pom file on your hard drive. Either way, you’ll need to get a ProjectBuilder, which you can do like so in a Mojo:

    /** @component role = "org.apache.maven.project.ProjectBuilder" */
    protected ProjectBuilder m_projectBuilder;
    

    If you want to build from an artifact in your local repo, you’ll also need:

    /** @parameter expression="${localRepository}" */
    protected ArtifactRepository m_localRepository;
    

    Once you have that, you can construct a MavenProject from an artifact from your local repository:

      //Construct the artifact representation
    Artifact artifact = 
        new DefaultArtifact(groupId,artifactId,version,scope,type,classifier,new DefaultArtifactHandler());
      //Resolve it against the local repository
    artifact = m_localRepository.find(artifact);
      //Create a project building request
    ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
      //Build the project and get the result
    MavenProject project = m_projectBuilder.build(artifact,request).getProject();
    

    Or from a pom file:

    File pomFile = new File("path/to/pom.xml");
    ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
    MavenProject project = m_projectBuilder.build(pomFile,request).getProject();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to programmatically set the constructor sting of a COM+ component from a
I need to check programmatically (in .NET) whether a given user (domain account) is
I have a case where I need to construct following structure programmatically (yes I
In a Java Project of mine, I would like to find out programmatically which
I want to be able to run all tests in a project programmatically. I
When programmatically issuing HTTP POST requests, what timeout values would be sensible? In my
I programmatically create a Picture Box in c# windows program. I assign it with
How programmatically create an element based on UserControl and dock it to the DockPanel?
I need to programmatically solve a system of linear equations in C, Objective C,
I'm programmatically adding ToolStripButton items to a context menu. That part is easy. this.tsmiDelete.DropDownItems.Add(The

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.