Share the joy
dependencies uses the dependencies.
dependencyManagement doesn’t include dependencies in project. It is mainly defines dependencies and its version, scope. Sub project specifies parent to it. When sub project defines dependencies, it won’t need to specify version, scope.
project1/pom.xml
This pom.xml has <packaging>pom</packaging> property. In this case, it can be used as parent in sub project.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test.pengli</groupId> <artifactId>project1</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> // This is needed if we want this pom.xml to be a parent <dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sts</artifactId> <version>2.17.74</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.6</version> </dependency> </dependencies> </project>
project2/pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.test.pengli</groupId> <artifactId>project1</artifactId> <version>1.0-SNAPSHOT</version> <relativePath>../project1</relativePath> </parent> <groupId>com.test.pengli</groupId> <artifactId>project2</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sts</artifactId> // No need to specify version. Parent pom did for us. </dependency> </dependencies> </project>
In project2, when run mvn dependency:tree, it shows below: