Stage 3 - Dependency Management: Working with Java Libraries

A backend rarely uses only JDK classes. It uses Spring, a database driver, a JSON library, a test framework, logging, validation, and many smaller libraries pulled in indirectly.

A dependency is an external artifact your project needs to compile, run, or test. Build tools identify it by coordinates: groupId, artifactId, and version.

Stage 3 - Dependency Management: Working with Java Libraries

Why this topic exists

Coordinates must be precise because many organizations publish artifacts with similar names. groupId identifies the group or company, artifactId identifies the library, and version identifies the exact release.

Scope controls where the dependency is visible. compile or Gradle implementation is used by production code. provided is available during compilation but supplied by the runtime environment. runtime is needed only when the app runs. test is available only for tests. system points to a local file and should almost never be used.

Transitive dependencies are dependencies of your dependencies. If you add Spring Web, you also get Jackson, logging libraries, validation integration, and servlet-related artifacts. This saves work, but it can also bring version conflicts.

A version conflict happens when two dependency paths request different versions of the same artifact. Build tools choose one version according to their resolution rules. You must still understand the tree because the chosen version may break runtime behavior.

Exclusions remove unwanted transitive dependencies. Version ranges allow flexible versions, but they reduce reproducibility and are usually avoided in application builds.

Build flow

  1. coordinates.
  2. scopes.
  3. transitive dependencies.
  4. conflict resolution.
  5. dependency tree.

This sequence is the mental model to keep while reading build files. The names are different in Maven and Gradle, but the practical question is the same: what input is used, what task runs, what output is produced, and where that output is stored.

Concrete example

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.7.4</version>
  <scope>runtime</scope>
</dependency>

Useful reference

Concept Meaning
compile / implementation Needed by production code.
provided Needed to compile, supplied by server/runtime.
runtime Needed when the app starts, not for compilation.
test Needed only for test code.
system Local file dependency; avoid in normal projects.

How this is used in real projects

The best habit is to inspect the dependency tree before guessing. In Maven use mvn dependency:tree; in Gradle use ./gradlew dependencies or dependencyInsight.

In a team setting, build knowledge is not optional theory. It affects local development, CI time, dependency upgrades, release stability, and debugging. When a Spring service fails to start after a dependency change, when CI downloads a different library version, or when an artifact cannot be deployed, the answer is usually in the build configuration, dependency graph, packaging step, or repository setup.

Common mistakes

  • Copying configuration without understanding which layer of the build it affects.
  • Treating a local successful build as proof that CI and production delivery will work.
  • Ignoring dependency trees, generated output, and repository rules until a release fails.
  • Mixing application runtime configuration with build-time configuration.
Glossary
build tool
A program that automates compiling, testing, packaging, dependency resolution, and other project build steps.
build
The process that turns source code, resources, tests, and configuration into a usable artifact.
Maven
A Java build tool based on conventions, lifecycles, plugins, and the `pom.xml` project model.
Gradle
A flexible build tool that uses tasks, plugins, build scripts, and incremental execution.
pom.xml
The Maven project file that describes coordinates, dependencies, plugins, properties, and build settings.
build.gradle
The Gradle build script that declares plugins, repositories, dependencies, tasks, and build configuration.
dependency
An external library or module that a project needs to compile, test, or run.
dependency coordinates
The group, artifact, and version values used to identify a dependency exactly.
scope
A Maven setting that defines where a dependency is available, such as compile, runtime, or test.
configuration
A Gradle dependency bucket, such as implementation or testImplementation.
transitive dependency
A dependency that is brought in indirectly because another dependency needs it.
dependency tree
A view that shows direct and transitive dependencies and helps diagnose version conflicts.
multi-module project
A project split into several modules that can share configuration and depend on each other.
parent project
A Maven project that centralizes shared configuration for child modules.
aggregator
A Maven project that lists modules and lets Maven build them together.
plugin
An extension that adds behavior to a build tool, such as compiling, testing, packaging, or publishing.
profile
A named build configuration variant used for different environments or build needs.
BOM
Bill of Materials, a dependency version catalog that keeps related libraries on compatible versions.
packaging
The build step and project setting that defines the output artifact type, such as JAR or WAR.
artifact
A built output such as a JAR, WAR, or published library version.
repository
A storage location where build tools download dependencies from or publish artifacts to.
Maven Central
The main public repository for Java and JVM libraries.
snapshot
A changing development artifact version that is not treated as a stable release.