Maven Plugin: accessing resources accross multiple modules

369 views Asked by At

I'm currently writing a custom maven plugin for generating a XML file in a multi-module maven project.

My maven structure is pretty standard: one parent project and a module by project components in the parent project folder:

-- Parent
  -- module A
  -- module B
  -- module C

I need to list, by module, a set of classes flagged by a custom annotation. I already wrote a set of custom annotations and an annocation processor to create a XML file at compile time in the corresponding module output directory (${project.build.outputDirectory}) .

Now i need to merge each module XML into one file, but i don't know how to access each modules from within my maven plugin except having each path set as parameters (i don't like this method).

Any idea on how to do this ? Does maven plugins can traverse project modules ?

Thank you in advance.

2

There are 2 answers

0
khmarbaise On BEST ANSWER

To get the list list of all projects you can use:

List<MavenProject> projectList = MavenSession.getProjectDependencyGraph().getSortedProjects()

If one of your goals is correctly executed you will get everything you need. Every MavenProject contains a getBaseDir() etc.

1
Lrk On

After some researches, it seems that MavenProject.getCollectedProjects() will return the list of projects beeing manipulated by a goal execution in a multi-module project.