DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Why I Started Using Dependency Injection in Python
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Understanding the Two Schools of Unit Testing

Trending

  • Scaling in Practice: Caching and Rate-Limiting With Redis and Next.js
  • How to Format Articles for DZone
  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  • From Fragmentation to Focus: A Data-First, Team-First Framework for Platform-Driven Organizations
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Dependency Management and Maven

Dependency Management and Maven

Achieving dependency management with Maven for multiple projects.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Nov. 03, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
13.7K Views

Join the DZone community and get the full member experience.

Join For Free

Maven is a great and mature build automation tool. There is always a solution on almost everything. The main case you might stumble on organization projects is dependency management. Instead of each project having its own dependencies you want a centralized way to inherit those dependencies.

In those cases, you declare on the parent prom the managed dependencies. In my example, I just want to include the Akka stream dependencies.

XML
 




x
41


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
    <modelVersion>4.0.0</modelVersion>
4
 
5
    <groupId>org.example</groupId>
6
    <artifactId>maven-dependency-management</artifactId>
7
    <packaging>pom</packaging>
8
    <version>1.0-SNAPSHOT</version>
9
 
10
    <properties>
11
        <akka.version>2.5.31</akka.version>
12
        <akka.http.version>10.1.11</akka.http.version>
13
        <scala.binary.version>2.12</scala.binary.version>
14
    </properties>
15
 
16
    <modules>
17
        <module>child-one</module>
18
    </modules>
19
 
20
 
21
    <dependencyManagement>
22
        <dependencies>
23
            <dependency>
24
                <groupId>com.typesafe.akka</groupId>
25
                <artifactId>akka-stream_2.12</artifactId>
26
                <version>${akka.version}</version>
27
            </dependency>
28
            <dependency>
29
                <groupId>com.typesafe.akka</groupId>
30
                <artifactId>akka-http_2.12</artifactId>
31
                <version>${akka.http.version}</version>
32
            </dependency>
33
            <dependency>
34
                <groupId>com.typesafe.akka</groupId>
35
                <artifactId>akka-http-spray-json_2.12</artifactId>
36
                <version>${akka.http.version}</version>
37
            </dependency>
38
        </dependencies>
39
    </dependencyManagement>
40
 
41
</project>



What I use is the dependency management block.

Now the child project would be able to include those libraries without specifying the version. Having the version derived and managed is essential. Many unpleasant surprises can come if a version is incompatible.

Now on to the child module the versions are declared without the version since it is the child module.

XML
 




xxxxxxxxxx
1
27


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
    <parent>
4
        <artifactId>maven-dependency-management</artifactId>
5
        <groupId>org.example</groupId>
6
        <version>1.0-SNAPSHOT</version>
7
    </parent>
8
    <modelVersion>4.0.0</modelVersion>
9
 
10
    <artifactId>child-one</artifactId>
11
 
12
    <dependencies>
13
        <dependency>
14
            <groupId>com.typesafe.akka</groupId>
15
            <artifactId>akka-stream_2.12</artifactId>
16
        </dependency>
17
        <dependency>
18
            <groupId>com.typesafe.akka</groupId>
19
            <artifactId>akka-http_2.12</artifactId>
20
        </dependency>
21
        <dependency>
22
            <groupId>com.typesafe.akka</groupId>
23
            <artifactId>akka-http-spray-json_2.12</artifactId>
24
        </dependency>
25
    </dependencies>
26
 
27
</project>



On another note sometimes we want to use another project’s dependency management without that project being our parent. Those are cases where you need to include the dependency management from a parent project when you already have a parent project.

XML
 




xxxxxxxxxx
1
36


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
 
4
    <modelVersion>4.0.0</modelVersion>
5
 
6
    <groupId>org.example</groupId>
7
    <artifactId>independent-project</artifactId>
8
    <version>1.0-SNAPSHOT</version>
9
 
10
    <dependencyManagement>
11
        <dependencies>
12
            <dependency>
13
                <artifactId>maven-dependency-management</artifactId>
14
                <groupId>org.example</groupId>
15
                <version>1.0-SNAPSHOT</version>
16
                <type>pom</type>
17
                <scope>import</scope>
18
            </dependency>
19
        </dependencies>
20
    </dependencyManagement>
21
 
22
    <dependencies>
23
        <dependency>
24
            <groupId>com.typesafe.akka</groupId>
25
            <artifactId>akka-stream_2.12</artifactId>
26
        </dependency>
27
        <dependency>
28
            <groupId>com.typesafe.akka</groupId>
29
            <artifactId>akka-http_2.12</artifactId>
30
        </dependency>
31
        <dependency>
32
            <groupId>com.typesafe.akka</groupId>
33
            <artifactId>akka-http-spray-json_2.12</artifactId>
34
        </dependency>
35
    </dependencies>
36
</project>



As you can see in the block

XML
 




xxxxxxxxxx
1
12


 
1
<dependencyManagement>
2
    <dependencies>
3
        <dependency>
4
            <artifactId>maven-dependency-management</artifactId>
5
            <groupId>org.example</groupId>
6
            <version>1.0-SNAPSHOT</version>
7
            <type>pom</type>
8
            <scope>import</scope>
9
        </dependency>
10
    </dependencies>
11
</dependencyManagement>
12

          



We just included the dependency management from another project, which can be applied to inherit dependencies from multiple projects.

We just achieved managing the dependencies for multiple projects using either a parent project or just another project.

Dependency

Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Why I Started Using Dependency Injection in Python
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Understanding the Two Schools of Unit Testing

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!