Maven Multi-Module Dependency Resolution | Generated by AI

Home 2025.10

Yes, that’s correct—in a Maven multi-module project, when one module (e.g., an EAR module) depends on another (e.g., a WAR module), Maven resolves the dependency from the local .m2/repository by default, not directly from the other module’s target/ directory. This is because Maven treats inter-module dependencies as standard artifact references (like external libs), so the dependent artifact must be installed (or at least packaged and discoverable via the build reactor).

Why This Happens

For WAR-to-EAR Packaging Specifically

In an EAR project:

Solution: Yes, you generally need to run mvn install (or at least mvn package in a full reactor build) on the “original” (dependency) module first if building independently. Best practices:

  1. Preferred: Build from Parent: mvn clean install at the project root. This installs everything to .m2 and handles ordering automatically.
  2. If Building Modules Separately:
    • cd war-module && mvn clean install (installs the WAR JAR to .m2).
    • Then cd ear-module && mvn clean package (or install—EARs often just need package).
  3. Avoid Direct Target Refs: Don’t hack around this with <systemPath> or file paths to target/—it’s brittle and skips Maven’s checksums/transitivity.

This behavior hasn’t changed in recent Maven versions (up to 3.9.x as of 2025). For more details, see the official multi-module guide.

Introduction to the Build Lifecycle - Multi-module Projects
Maven EAR Plugin Documentation


Back

x-ai/grok-4-fast

Donate