Is it possible to get an instance of org.apache.maven.project.MavenProject
or some other object form of the POM from just the pom.xml file?
Thanks in advance.
Is it possible to get an instance of org.apache.maven.project.MavenProject
or some other object form of the POM from just the pom.xml file?
Thanks in advance.
yes you can . This is the code. You need maven-model-3.0.4.jar and plexus-utils-2.0.6.jar and maven-core-3.0.4.jar
Model model = null;
FileReader reader = null;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
reader = new FileReader(pomfile);
model = mavenreader.read(reader);
model.setPomFile(pomfile);
}catch(Exception ex){}
MavenProject project = new MavenProject(model);
If you want to get the MavenProject based on groupid, artifactId and version you have to run inside of a maven plugin. And this code will do the job:
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
configuration.setProcessPlugins( false );
configuration.setRepositorySession( session );
org.apache.maven.artifact.Artifact artifact = new org.apache.maven.artifact.DefaultArtifact(groupId, artifactId, version, "compile", "", "", new DefaultArtifactHandler());
MavenProject project = projectBuilder.build(artifact, configuration).getProject();
The missing properties can be injected into the maven plugin.