Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use POMs as a dependency in Maven?

Is there a way to add a pom type dependency to my POM and get all its modules?

JavaMail is a good example. Maven Central Repo has a parent POM called: com.sun.mail:all:1.5.0 with modules: mail, mailapi, mailapijar, smtp, imap, gimap, pop3, and dsn.

However, the "all" artefact only has a single file: pom.xml Is there a way to add this "all" artefact as a dependency to my POM and get all its modules? I am 90% sure this is not the right way to use dependencies in Maven, but I want to hear it from an expert on The Stack.

Ideas:

  • <dependencies><dependency>...<type>pom</type></dependency></dependencies>
  • <dependencyManagement><dependencies><dependency>...<type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

Related: Netbeans: maven dependencies of type pom

like image 856
kevinarpe Avatar asked Jun 03 '13 09:06

kevinarpe


People also ask

What is POM xml dependency?

POM is an acronym for Project Object Model. The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.


1 Answers

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.

like image 198
Guillaume Darmont Avatar answered Sep 26 '22 04:09

Guillaume Darmont