javamavenmaven-reactor

Can `mvn compile` be expected to work with multi-module Maven reactor builds?


Can mvn compile be expected to work with multi-module Maven reactor builds?

I am trying to work on a project that uses a reactor/multi-module Maven build. When mvn compile failed*, I was told by persons familiar with the project that mvn install is needed, and not mvn compile, because it is a reactor build.

While mvn install indeed works because Maven can then pull the build dependency out of the local repository, it seems wrong to me that I must publish to the repository since doing so can create problems, especially in CI environments.

However, nearly every example I can find surrounding a multi-module project uses mvn clean install, including Maven by Example. I have found no examples of mvn compile that I can attribute to multi-module projects, making me inclined to think there is a Maven limitation/requirement here.

I note that mvn compile did work for me with the example provided in Maven by Example, but that is a relatively simple project so I know I cannot take that to mean it should work in general.

* It failed because it could not find one of the dependencies that was built successfully earlier in the reactor build.


Solution

  • As indicated in @khmarbaise's comment and demonstrated by the fact it works with the Maven By Example example. mvn compile and mvn test can work with reactor builds.

    However, not all plugins work well with this approach. For example, making test-jar's work can require changing the phase.

    Using mvn package as suggested by @khmarbaise is likely to give far fewer of these issues while also avoiding the problems caused by using mvn install or mvn deploy.