I usually put a <dependencyManagement>
section in parent-project/pom.xml
. This <dependencyManagement>
section contains declaration and version for all dependencies of my children modules like this (i.e. without the <scope>
element):
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
</dependencyManagement>
In all children modules (i.e. moduleX/pom.xml), I have:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Obviously, in this example I'm repeating the <scope>test</scope>
multiple times for the same dependency (once in every child module needing junit).
My question is:
What are the best practices regarding <scope>
declaration?
Is it better to put it in the <dependencyManagement>
?
Or is it better to put it in the <dependencies>
section of the child module (like in this post)? And why?
Is there any definitive answer to this question?