Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Java builds (Maven, Gradle, JAR, WAR)

What are transitive dependencies and how do you see the dependency tree?

IntermediateConceptJava builds (Maven, Gradle, JAR, WAR)
Answer

Short answer

A transitive dependency is a library your dependency needs. If you add spring-boot-starter-web, Maven also pulls in Tomcat, Jackson, Spring Core and dozens more — you never listed them, but they come along. mvn dependency:tree shows the full tree.

Example

mvn dependency:tree
com.shop:orders:jar:1.4.0
+- org.springframework.boot:spring-boot-starter-web:jar:3.3.0:compile
|  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.3.0:compile
|  |  \- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.24:compile
|  \- com.fasterxml.jackson.core:jackson-databind:jar:2.17.1:compile
\- org.postgresql:postgresql:jar:42.7.3:runtime

Why it matters for DevOps and security

  • Vulnerabilities often hide in transitive dependencies. Log4Shell (CVE-2021-44228) hit many apps that never added log4j directly.
  • Version conflicts: two libraries may want different versions of the same library. Maven picks the nearest one in the tree, which can break things.

Fixing a vulnerable transitive dependency

<dependencyManagement>
  <dependencies>
    <dependency>                         <!-- force a safe version everywhere -->
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.17.2</version>
    </dependency>
  </dependencies>
</dependencyManagement>

Or exclude it with <exclusions> if it isn't needed.

What to say in the interview

"Transitive dependencies are the dependencies of my dependencies. I inspect them with mvn dependency:tree, and when a scanner like Trivy or OWASP Dependency-Check flags a vulnerable one, I pin a fixed version in dependencyManagement or exclude it."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

More on Java builds (Maven, Gradle, JAR, WAR)