Skip to content

Instantly share code, notes, and snippets.

@reiz
Created August 11, 2013 06:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save reiz/6203767 to your computer and use it in GitHub Desktop.
Save reiz/6203767 to your computer and use it in GitHub Desktop.
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 = projectBuilder.build(artifact, 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