17

I've seen a lot of chatter regarding setting an env parameter maven.multiModuleProjectDirectory, both on SO and on Maven mailing lists, but I am having trouble understanding exactly what this setting does/is used for.

I've searched google, maven sites, docs, etc, but can't seem to find a reference that actually explains what this parameter is for, or how to leverage it.

Can anyone either explain it's purpose and/or point me to the documentation for it? In which version of maven was it introduced?

Eric B.
  • 23,425
  • 50
  • 169
  • 316

1 Answers1

13

The environment variable has been introduced in Maven 3.3.1 which is available from within the mvn script or mvn.cmd script. The intention is to find the start of a multi module structure where the .mvn location can be found.

This was introduced to make configuration within the project possible instead from outside.

Take a look into the Maven 3.3.1 release notes.

Update This variable is only used in the mvn script and is neither documented nor intended for public used (internal implementation detail). So I strongly recommend not to use it. Otherwise things might break in the future.

Gama11
  • 31,714
  • 9
  • 78
  • 100
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 3
    Thanks. I had read the full 3.3.1 release notes but it didn't mention anything about the multiModuleProjectDirectory var. So, if I understand this correctly, given settings in the `.mvn` folder, if I were to attempt to build a submodule independently (and not from the root), I would specify this var such that maven could find my `.mvn` in my tree. However, if I launch maven from the project root, this var would no longer be necessary. Correct? – Eric B. Apr 21 '15 at 18:55
  • 1
    Building a submodule is done by `mvn -pl ...` which does not change anything. Apart from that no you don't need to specify this, cause it's handled internally by the scripts and that's the reason why it is not metioned in the release notes, cause you usually don't need to bother about that. It is necessary cause it's internally used to find the root folder for multi module builds. – khmarbaise Apr 22 '15 at 06:49
  • 2
    Indeed I can use `mvn -pl ...`, but there is also the option of running `mvn` directly in the module subdirectory and not from the multi-module root. Or is that considered bad practice in a multi-module build? – Eric B. Apr 22 '15 at 14:06
  • 1
    I doubt it's a bad practice. It's just another way of getting things done. – Krzysztof Jabłoński Jul 14 '17 at 09:53
  • The thing is if you run in sub directory you don't have the relationship to other modules in your source tree nor eventually the need for rebuilding of other modules which Maven handles automatically...if you add things like `-amd -am` and that's what most people forget about... – khmarbaise Jul 17 '17 at 12:27
  • 3
    Usage with maven-embedder: https://stackoverflow.com/questions/33400574/unable-to-run-maven-tasks-through-mavencli-maven-embedder – AlexO Sep 20 '17 at 00:41
  • FYI - saw this problem in a repo at work. Upgrading PMD to 3.20.0 meant it correctly found the ruleset in the top level. – cs94njw Jun 29 '23 at 13:20