<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Geetha Krishna on Medium]]></title>
        <description><![CDATA[Stories by Geetha Krishna on Medium]]></description>
        <link>https://medium.com/@chgeethakrishna?source=rss-cba8f9a8790a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-4czuSQZgr4ywd6rgcsS_w.png</url>
            <title>Stories by Geetha Krishna on Medium</title>
            <link>https://medium.com/@chgeethakrishna?source=rss-cba8f9a8790a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 02:51:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chgeethakrishna/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Maven: Transitive Dependencies]]></title>
            <link>https://medium.com/@chgeethakrishna/maven-transitive-dependencies-d15037a69a8f?source=rss-cba8f9a8790a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d15037a69a8f</guid>
            <category><![CDATA[maven]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Geetha Krishna]]></dc:creator>
            <pubDate>Tue, 28 Oct 2025 18:06:16 GMT</pubDate>
            <atom:updated>2025-10-28T18:09:36.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*awwPdCABr2E4TJqy" /><figcaption>Photo by <a href="https://unsplash.com/@joyceromero?utm_source=medium&amp;utm_medium=referral">Joyce Romero</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Overview</h3><p><em>Maven is one of the most used build tools in the Java ecosystem, one of its core features is dependency management. Maven avoids the need to discover and specify the libraries your own project dependencies require by including transitive dependencies automatically.</em></p><p>As projects grow in complexity, managing dependencies can become a head-ache. This guide provides an in-depth explanation of what transitive dependencies are, how Maven resolves them, common challenges, and practical guidance for working with them effectively.</p><h3>What are Transitive Dependencies?</h3><p>In Maven, a <strong><em>transitive dependency</em></strong> is a dependency of a dependency. This means:</p><ul><li>Assume your project depends on <strong>Dependency A</strong></li><li>and <strong>Dependency A</strong>depends on <strong>Dependency B</strong></li><li>then your project implicitly depends on <strong>Dependency B</strong>(transitive dependency) as well</li></ul><p>Maven automatically includes these transitive dependencies in your project build, so you do not have to explicitly declare every library your project needs.</p><h3>How Maven Resolves Transitive Dependencies?</h3><p>Maven builds a dependency graph starting from your direct dependencies to their dependencies, recursively, with no fixed depth limit. It fetches all required libraries from remote repositories and adds them to your project’s classpath.</p><ul><li>Maven reads the pom.xml of each dependency to know what libraries it requires</li><li>This recursive loading results in a comprehensive set of libraries needed for your project</li><li>Sometimes this can lead to conflicts if different dependencies require different versions of the same library</li></ul><pre>Your Project<br> ├─ Dependency A<br> │ └─ Dependency B (version 1.0)<br> └─ Dependency C<br> └─ Dependency B (version 2.0)</pre><p>In this scenario maven uses <strong>dependency mediation</strong> to decide which version of <strong>Dependency B</strong>to use.</p><h3>Dependency Mediation and Conflict Resolution</h3><p>When multiple versions of the same library appear due to transitive dependencies, Maven applies these rules:</p><ul><li><strong>Nearest declaration wins: </strong>Maven uses the version that is closer to your project in the dependency tree</li><li>If two versions are at the same depth, Maven uses the one declared first in the pom.xml</li></ul><p>You can override the selected version by explicitly declaring it as a dependency in your own pom.xml either under dependencies or <a href="https://medium.com/@chgeethakrishna/ccd782d3b39c">dependencyManagement</a>.</p><pre>&lt;dependency&gt;<br>  &lt;groupId&gt;some.group&lt;/groupdId&gt;<br>  &lt;artifactId&gt;some-dependency&lt;/artifactId&gt;<br>  &lt;version&gt;2.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><blockquote>Dependency scope also determines how dependencies (including transitive) are included in your build and runtime classpath. More on it <a href="https://medium.com/@chgeethakrishna/7ddc5bea6e17">here</a>.</blockquote><h3>Common Challenges with Transitive Dependencies</h3><ol><li>Different versions of the same library can cause build or runtime issues. Use mvn dependency:tree to analyze conflicts</li><li>Automatically including all the transitive dependencies may pull in unnecessary libraries, increasing build size</li><li>If a transitive dependency has provided scope, it won’t be included in the packaged artifact, possibly causing ClassNotFoundException</li></ol><h3>Tips for Working with Transitive Dependencies</h3><ul><li>Use mvn dependency:tree to visualize and debug your project’s dependency graph</li><li>To exclude unwanted transitive dependencies, use the &lt;exclusions&gt; tag</li></ul><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;com.example&lt;/groupId&gt;<br>    &lt;artifactId&gt;some-lib&lt;/artifactId&gt;<br>    &lt;version&gt;1.0.0&lt;/version&gt;<br>    &lt;exclusions&gt;<br>        &lt;exclusion&gt;<br>            &lt;groupId&gt;org.unwanted&lt;/groupId&gt;<br>            &lt;artifactId&gt;unwanted-lib&lt;/artifactId&gt;<br>        &lt;/exclusion&gt;<br>    &lt;/exclusions&gt;<br>&lt;/dependency&gt;</pre><ul><li>Manage versions centrally in &lt;dependencyManagement&gt;</li></ul><p>The &lt;dependencyManagement&gt; section allows you to specify (lock) versions that will apply accross all modules, or force a specific version in case of conflicts</p><pre>&lt;dependencyManagement&gt;<br>    &lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;commons-logging&lt;/groupId&gt;<br>            &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;<br>            &lt;version&gt;1.2&lt;/version&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;<br>&lt;/dependencyManagement&gt;</pre><p>Any module or dependency that requires commons-logging will use version 1.2 , regardless of what is specified in transitive dependencies</p><ul><li>Be cautious with scope to avoid missing needed libraries or including unnecessary ones</li></ul><pre>&lt;project&gt;<br>  ...<br>  &lt;dependencies&gt;<br>    &lt;!-- Main dependency --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>      &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>      &lt;version&gt;3.1.0&lt;/version&gt;<br>      &lt;!-- Exclude a problematic transitive dependency --&gt;<br>      &lt;exclusions&gt;<br>        &lt;exclusion&gt;<br>          &lt;groupId&gt;commons-logging&lt;/groupId&gt;<br>          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;<br>        &lt;/exclusion&gt;<br>      &lt;/exclusions&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;!-- Add the desired version explicitly --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;commons-logging&lt;/groupId&gt;<br>      &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;<br>      &lt;version&gt;1.2&lt;/version&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;!-- Test scope dependency (not included in final artifact) --&gt;<br>    &lt;dependency&gt;<br>      &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;<br>      &lt;artifactId&gt;junit-jupiter&lt;/artifactId&gt;<br>      &lt;version&gt;5.10.1&lt;/version&gt;<br>      &lt;scope&gt;test&lt;/scope&gt;<br>    &lt;/dependency&gt;<br>  &lt;/dependencies&gt;<br>&lt;/project&gt;</pre><h3>References</h3><ul><li><a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d15037a69a8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>