Maven
02 / 02

Multi-Module Builds, BOMs & Profiles

Multi-Module Builds, BOMs & Profiles

Multi-Module Projects

<!-- parent pom.xml -->
<project>
  <groupId>com.example</groupId>
  <artifactId>my-platform</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>

  <modules>
    <module>core</module>
    <module>web</module>
    <module>api</module>
  </modules>
</project>

<!-- web/pom.xml — declares the parent, can depend on sibling modules -->
<project>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>my-platform</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>web</artifactId>
  <dependencies>
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>core</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

<!-- Reactor computes the correct build order from these dependencies -->
<!-- mvn -T 4 install   — parallelize modules with no dependency relationship -->

Dependency Management & BOMs

<!-- Parent POM — declares versions WITHOUT adding the dependency itself -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>33.0.0-jre</version>
    </dependency>
  </dependencies>
</dependencyManagement>

<!-- Child module — omits the version, inherits the managed one -->
<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
</dependency>

<!-- Importing a BOM — pulls in a whole curated, mutually-compatible version set -->
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>3.2.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

Profiles & Plugin Binding

<profiles>
  <profile>
    <id>production</id>
    <properties>
      <env>prod</env>
    </properties>
  </profile>
</profiles>
<!-- mvn package -Pproduction -->

<!-- Binding a plugin execution to a lifecycle phase — runs automatically,
     no manual step required, in the correct order relative to compile -->
<build>
  <plugins>
    <plugin>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals><goal>generate</goal></goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free