How to use POMs as a dependency in Maven?

You have to go with

<dependencies>
  <dependency>
     <groupId>com.my</groupId>
     <artifactId>commons-deps</artifactId>
     <type>pom</type>
  </dependency>
</dependencies>

This will transitively add all dependencies declared in com.my:commons-deps to your current POM.

Using

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

works as a simple ‘include’ of artifacts versions in your dependency management. Thus, it won’t add any dependency in your project.

Leave a Comment