Managing dependencies in Maven means declaring the libraries a project needs inside the <dependencies> section of pom.xml, letting Maven handle downloading, versioning, and resolving transitive dependencies automatically.
Key Points: • Each dependency is identified by groupId, artifactId, and version, mirroring how the artifact itself is published. • Maven resolves the full dependency graph, including transitive dependencies pulled in by your direct dependencies. • The scope element (compile, test, provided, runtime) controls when a dependency is available — test scope, for example, excludes it from the packaged artifact. • In multi-module projects, a parent POM's <dependencyManagement> section centralizes version numbers so child modules just reference groupId and artifactId. • Running mvn dependency:tree shows the full resolved graph, useful for spotting version conflicts.
Example: Adding JUnit as a test-only dependency means declaring it with scope test, so it's available for compiling and running tests but excluded from the final packaged jar.
Code Example:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>Interview Tip: A concise interview answer is:
"Dependencies are declared in the dependencies section of pom.xml with a groupId, artifactId, and version, and Maven automatically downloads them plus their transitive dependencies. Scope controls when each one is available, like test scope keeping JUnit out of the final packaged artifact."