Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Creating a MavenProject from an ArtifactInfo inside a maven plugin.
protected MavenProject buildProjectModel(ArtifactInfo artifactInfo) throws Exception {
try {
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
configuration.setLocalRepository( localRepository );
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
configuration.setProcessPlugins( false );
configuration.setRepositoryMerging( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT );
Properties properties = new Properties( );
for ( String key : session.getSystemProperties( ).keySet() ){
properties.put( key, session.getSystemProperties().get(key) );
configuration.setSystemProperties( properties );
configuration.setRepositorySession( session );
org.apache.maven.artifact.Artifact artifact = new org.apache.maven.artifact.DefaultArtifact(
artifactInfo.groupId, artifactInfo.artifactId,artifactInfo.version,
"compile", "", "", new DefaultArtifactHandler());
MavenProject project =, configuration).getProject();
return project;
} catch (Exception ex) {
getLog().error("error in buildProjectModel ", ex);
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment