3

I'm curious if it's possible to build and analyze the submodules of my multi-module maven project with a single command.

For the time being I have a single maven project with 3 separate services underneath it. Think of it like a small-scale monorepo.

Currently when I build them I can run a single mvn clean install from the top-most project and get a full build of everything with distinct JaCoCo analysis of all 3 services. In other maven projects where I already only have a single service I can simply run mvn clean install sonar:sonar but when I run it in my multi-module project it only executes at the top most level and analyses all 3 services as a single project in Sonar/SonarQube.

This answer seems to indicate it's impossible to do the same thing for a multi-module build with a single command but it's also a very old answer and things may have changed since then but with codehaus shutdown I don't think I can find that jira issue easily.

Also trying to implement the answer to that question using pluginManagement and enabling/disabling skip in parent/child modules doesn't seem to be working since sonar sees the parent as being skipped and then skips all children. It may work for exec but sonar seems to aggregate/iterate submodules differently.

The next obvious solution indicated by these questions, and to a degree the Sonar documentation itself since the deprecation of sonar.includeModules/sonar.excludeModules in 4.3 is to use Maven's advanced reactor options however that doesn't work for skipping the parent project. Trying to run mvn sonar:sonar -pl one,two,three, or the opposite mvn sonar:sonar -pl !. throws the error:

Maven session does not declare a top level project

Maven does seem to constrain itself to the correct list of modules but sonar itself seems incompatible with the approach and throws the error at the first module.

So now the answer seems to be that I need to run mvn sonar:sonar individually once per module in each module's directory, which is just a bit obnoxious.

Sloloem
  • 1,587
  • 2
  • 15
  • 37

0 Answers0