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

maven multi module project dependencies between modules
what will be the build order for the below multi-module project?
maven multi module best practices
maven multi module project example
in maven, ________ is a child or subproject, which is part of a larger project.
maven multi module project spring boot
maven build selected modules
create maven multi module project intellij

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.

You can use --also-make-dependents option. It configures Maven to build the project and its dependents. Actually, the command examines all of the projects in reactor to find projects that depend on a particular project. It will automatically build those projects and nothing else.

$ mvn --projects your-sample-project --also-make-dependents install

Resource Link: Maven Tips and Tricks: Advanced Reactor Options

Maven Modules + Building a Single Specific Module, How do I run a multi module project in Maven? The mechanism in Maven that handles multi-module projects is referred to as the reactor. This part of the Maven core does the following: Collects all the available modules to build; Sorts the projects into the correct build order; Builds the selected projects in order; Reactor Sorting. Because modules within a multi-module build can depend on

If your multi-module project has interdependencies on each other it is actually quite logical that you need to at least install these dependencies to your local repository before others are compile-able.

maven - two different root poms, will take the already packaged and installed dependencies just right. Some commands to a build a multi-module project, for examples : $ mvn -pl password compile # compile password module only $ mvn -pl password-sha compile # compile password-sha module, also dependency - password $ mvn -pl web compile # compile web module only $ mvn -am -pl web compile # compile web module, also dependency - password-sha or

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.

Skip a submodule during a Maven build, quote it (like I did) or escape it with the backslash character. I have a multi-module Maven project with a parent project P and three sub-modules A, B, and C. Both B and C are war projects and both depend on A. I can type mvn compile in P and have all of the sub-modules properly compiled. The problem comes when I want to do operations for specific modules.

I have run into this issue for multi-module projects. For example, I'll have a module called base that every other module depends on, for both normal scope as well as test scope. The test scope dependency is there so I can share common unit test classes and utilities.

The mvn compile will fail with on the test-scoped deps with a message like Could not resolve dependencies for project com.example:zydeco:jar:0.0.1: Failure to find com.example:base:jar:tests:0.0.1

However using mvn test -Dmaven.test.skip.exec=true, which is in spirit the same as compile, and it will find resolve all intra-project test dependencies just fine.

If I run something like mvn dependency:tree, it will fail for regular dependencies with a message like Could not resolve dependencies for project com.example:zydeco:jar:0.0.1: Failure to find com.example:base:jar:0.0.1

I agree with other folks that avoiding package and install is desirable - to avoid having stale code lying around. In the past, I've actually written scripts which create empty/fake jar files so that commands like mvn dependency:build-classpath can work.

I'm not sure there is away around this with maven. It's on my list to look at sbt and gradle.

Maven – Guide to Working with Multiple Modules, Builds the selected projects in order. Reactor Sorting. Because modules within a multi-module build can depend on each other, it is important that the reactor sorts​  The reactor is the part of Maven that allows it to execute a goal on a set of modules. As mentioned in the Maven 1.x documentation on multi-modules builds (the reactor concept was already there in Maven 1.x), while modules are discrete unit of work, they can be gathered together using the reactor to build them simultaneously and:

Multi-Module Project with Maven, Learn about the benefits of using a Maven multi-module project and walk Now, we work on both of them and change functionality which affects the two. Therefore, when leveraging multi-modules, we can build our mvn archetype:​generate -DgroupId=org.baeldung [INFO] Reactor Build Order:. Rich is totally right. What you describe is generally not the expected behaviour. Although, as stated by deterb, the Maven reactor supports partial builds if the modules are known by the parent POM. Building with mvn install -pl B -am should also make (-am) B's dependencies (that is, A). Anyway, module A must be a module of the parent POM.

Module-to-module dependencies in a multi-module maven file are , GitHub is home to over 50 million developers working together to host Based on the multi-module example you run mvn compile jib:build but Expected behavior: Since maven doesn't surface the dependency through the reactor we can check for multimodule builds with intermodule dependencies  mvn -Pitest -pl :A1 -amd clean install Reference. Maven has many other command line options such as -o, -fae and -rf that can be used to tweak and improve your builds if used wisely. See the Maven command line help for reference, or simply execute Maven with the -h (or --help) option: mvn -h

Orb not working well for multi-module project · Issue #4 · CircleCI , Orb Version 1.0.0 Describe the bug Fetching dependencies in commands/​with_cache.yml will fail for multi-module maven project because the  Now it’s time to build our multi module project and before building let’s see about the reactor in Maven. The Reactor. Maven handles multi-module projects using a concept “reactor”. This part of the Maven called “reactor” does the following: Collects all the available modules to build; Sorts the projects into the correct build order

  • which version of maven are you using?
  • Apache Maven 3.5.2
  • As far as I know, maven needs to put built artifact into local repo in order to be able to find it if it is used as dependency for other project even for multy module projects. I am not sure why you dont want the artifact to be in the local repo?
  • @tsolakp Consider a CI Server, machine-local means global to all the builds on that server. By doing an install the compilation artifacts of one build become visible to another build. This means a mis-configured build could wrongly succeed because it could pull dependencies from the local repo. Or another build could fail when it should have passed because of differences between the local repo copy from a build and the remotely-published dependency that was expected.
  • A multi module project is usually being built by using mvn clean package. The install is only necessary if any other project (unrelated to the modules in the reactor) will use one or more of the built projects as dependencies...
  • That still uses install and not compile, so I am not sure what is gained
  • From documentation, mvn install - This command executes each default life cycle phase in order (validate, compile, package, etc.), before executing install.
  • The point of my question is that I don't want to execute install.
  • Actually you are mixing normal maven project and multi module project. . And in reactor[The Reactor takes care of ordering components to ensure that interdependent modules are compiled and installed in the proper order.] Please go through: Guide to Working with Multiple Modules
  • Are you saying that something is configured, making it a mixed build, therefore compile does not work and otherwise it would? Unless I am missing navigation the guide you linked is just a single page that does not appear to answer the question.
  • Would it not also be logical for Maven to recognize it just built a component and use the just built version?
  • Not really. Maven Separates concerns. Therefore if a module (A) has a dependency on another module (B). This other module (B) needs to be available for module (A) to compile...
  • Which is why the reactor figures out that that B needs to be built first and builds it before A.
  • An install is for a multi module built not needed. Only mvn clean package. If it is really needed than your multi module build is broken (missing inter module dependencies)...