Hi,

I'm looking for a way to launch Maven programmatically in such a way that I
can get access to fully resolved Model and MavenProject instances, and not
just for a single project but also for all projects that belong to a
Reactor.

At first I used this code

try {
    FileReader reader = new FileReader(pom);
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    return new MavenProject(mavenReader.read(reader));
} catch (Exception e) {
    throw new IllegalArgumentException(e);
}

But of course that's not enough. Next I tried using the maven-model-builder
APIs directly but not all references get resolved (such as parent POMs) as
a custom ModelResolver is required and the default one is not intended to
be used in standalone fashion.

Ideally I would call some sort of embeddable Maven API that can give me the
answers I seek, something like this

MavenProject project = EmbeddableMaven.launch(propsOrFlags).file(pomFile);

or alternatively something like

MavenReactor reactor = EmbeddableMaven.launch(propsOrFlags).file(pomFile);
for(MavenProject project : reactor.getProjects()) { /* do stuff */ }

Of course I'm making up these types and method names as I do not know if
something like this exist or not, hence why I'm asking here.

Thanks in advance.

Cheers
Andres

Reply via email to