Created
August 11, 2013 06:52
-
-
Save reiz/6203767 to your computer and use it in GitHub Desktop.
Creating a MavenProject from an ArtifactInfo inside a maven plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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