Hi, That's the way to do it There is a library to ease that here https://github.com/jenkinsci/lib-jenkins-maven-embedder/tree/master
cheers Olivier On Fri, 17 Apr 2020 at 13:04, Tomo Suzuki <[email protected]> wrote: > I'm interested in that problem too. In the project below, we use > PlexusContainer to instantiate MavenProject class from pom file: > > https://github.com/GoogleCloudPlatform/cloud-opensource-java/blob/master/dependencies/src/main/java/com/google/cloud/tools/opensource/dependencies/RepositoryUtility.java#L209 > > I hope there's a better way to achieve this. > > On Thu, Apr 16, 2020 at 6:55 AM Andres Almiray <[email protected]> wrote: > > > 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 > > > > > -- > Regards, > Tomo > -- Olivier Lamy http://twitter.com/olamy | http://linkedin.com/in/olamy
