I am using Maven embedder 3.3.3 in my program to run maven goals programmatically and I get the following error every time I run the MavenCli.doMain method:
-Dmaven.multiModuleProjectDirectorysystem property is not set. Check$M2_HOMEenvironment variable andmvnscript match.
Since Maven 3.3.1, there is a new system property called
maven.multiModuleProjectDirectory. It is set by default to the root of the project (project base directory) by themvn(ormvn.bat) script (so that is why you never experienced such an error before).Therefore, when running Maven through
maven-embedder, you also need to set this system property (see source code where the check is made). It needs to be set to the project root.To set this system property, you can adjust your call to
doMainand addto the given arguments. An example would be
Alternatively, you can call:
before invoking
MavenCli.doMainmethod, whereprojectRootpoints to root of the project you are building.