Dependency Management
Configurations such as api and implementation, version catalogs, resolution and conflict rules, repositories, and dependency verification. Interviewers focus here because Gradle resolves differently from Maven and candidates often assume otherwise.
on this pageshowhide
explore
- Declaring Dependencies30 questions
- Dependency Configurations5 questions
- Configuration Roles5 questions
- Dependency Notation5 questions
- Project and File Dependencies5 questions
- Test Fixtures Dependencies5 questions
- Exclusions and Transitivity Control5 questions
- Versions and Catalogs36 questions
- Version Catalog TOML6 questions
- Type-Safe libs Accessors5 questions
- Declaring and Sharing Catalogs5 questions
- Platforms and BOMs5 questions
- Dynamic and Changing Versions5 questions
- Rich Version Declarations5 questions
- Dependency Version Alignment5 questions
- Resolution and Conflicts41 questions
- Default Conflict Resolution6 questions
- Forcing and Strict Constraints5 questions
- Resolution Strategy and eachDependency5 questions
- Dependency Substitution5 questions
- Capabilities and Conflicts5 questions
- Dependency Locking5 questions
- Resolution Result and Artifact View5 questions
- Module Replacement5 questions
- Repositories and Metadata42 questions
- Declaring Repositories6 questions
- Centralized Repository Management5 questions
- Repository Content Filtering5 questions
- Authenticated Repositories5 questions
- Gradle Module Metadata5 questions
- Variant-Aware Resolution5 questions
- Component Metadata Rules6 questions
- Dependency Cache5 questions
- Artifact Transforms10 questions
- TransformAction Implementation5 questions
- Registering and Attribute Matching5 questions
- Verification and Integrity20 questions
- Verification Metadata File5 questions
- Checksum Verification5 questions
- PGP Signature Verification5 questions
- Bootstrapping and Maintaining Verification5 questions
questions
179 · 6 sectionsYou try to resolve `implementation` and get an error that it cannot be resolved. Why, and what should you resolve instead?
basics
~10 simplementation is a declaration bucket — isCanBeResolved is false — so it has no resolution result. Resolve compileClasspath or runtimeClasspath, which extend from it.
What is the `dependencies {}` block in a Gradle build script, and how do you add a dependency to a specific configuration inside it?
basics
~10 sThe dependencies {} block is where you declare a module's dependencies. Inside it you call a configuration name like implementation(...) with the dependency coordinates (group:name:version) to attach a dependency to that configuration.
How do `testImplementation` and `testRuntimeOnly` relate to the main source set's configurations, and when do you use each?
basics
~20 stestImplementation adds a dependency to the test compile + runtime classpath (e.g. JUnit, Mockito). testRuntimeOnly adds it only to the test runtime classpath (e.g. the JUnit Platform launcher engine). Test classpaths also extend the main ones.
How do you exclude a single transitive dependency that is pulled in by one specific dependency in Gradle?
basics
~10 sAttach an exclude block to that one dependency, naming the unwanted artifact by group and/or module. Only that dependency's transitive graph is affected.
What does the string dependency notation 'group:name:version' mean in Gradle, and how do you declare such a dependency?
basics
~10 sIt's the shorthand for a module's coordinates: group (org), name (artifact), version. You declare it inside a configuration, e.g. implementation("org.apache.commons:commons-lang3:3.14.0").
What does 'dependency version alignment' mean in Gradle, and why might you need it for a dependency family like Jackson?
basics
~10 sAlignment forces all modules of one library family (e.g. all jackson-* artifacts) to resolve to the same version, instead of a mix, avoiding runtime incompatibilities between modules built to be released together.
What is a Gradle version catalog and where does the default `libs` catalog come from?
basics
~10 sA version catalog is a central, typed list of dependency coordinates and versions shared across a build. Gradle auto-creates the libs catalog from gradle/libs.versions.toml if that file exists.
What is the gradle/libs.versions.toml file, and what are the four tables it can contain?
basics
~10 sIt's Gradle's version catalog: a TOML file at gradle/libs.versions.toml listing dependency coordinates and versions in one place. Its four tables are [versions], [libraries], [bundles], and [plugins].
What is the difference between a dynamic version and a changing version in Gradle dependency management?
basics
~20 sA dynamic version lets Gradle pick which version to resolve (e.g. '1.+', 'latest.release'). A changing version is one fixed coordinate whose artifacts can change over time (e.g. '-SNAPSHOT'), so the same version number may hold different content.
What does the platform() dependency notation do in Gradle, and what is a typical use for it?
basics
~10 splatform() imports a Maven BOM so its version constraints apply to your dependencies, letting you declare those dependencies without versions and keep them aligned.
When two transitive dependencies require different versions of the same module, what does Gradle do by default?
basics
~10 sBy default Gradle picks the highest requested version of the module and uses that single version everywhere on the classpath. This is 'highest-version-wins' conflict resolution.
What does `resolutionStrategy.force('com.google.guava:guava:32.1.3-jre')` do, and when would you reach for it?
basics
~10 sIt pins Guava to exactly that version for the whole configuration, overriding whatever version conflict resolution would otherwise pick — even if another dependency wants a higher one.
What is dependency locking in Gradle, and why would you enable it?
basics
~20 sDependency locking pins the exact versions a configuration resolves to, saving them in a lockfile. With dynamic versions or version ranges, builds can drift over time; locking makes resolution reproducible across machines and over time.
What is dependency substitution in Gradle, and what problem does it solve?
basics
~20 sDependency substitution lets you swap one dependency for another during resolution — for example, replacing a published external module with a local project so you build and test against your own source instead of a release.
What is a 'capability' in Gradle dependency management, and what problem does it solve compared to plain version conflict resolution?
basics
~20 sA capability is a label (group:name:version) saying 'I provide this feature'. By default a module provides one capability matching its GAV. Two modules offering the same capability conflict, even if they are different modules — like log4j and log4j-over-slf4j both providing logging.
Where does Gradle store downloaded dependencies, and what is the purpose of that cache?
basics
~10 sGradle stores downloaded artifacts and metadata under GRADLE_USER_HOME/caches/modules-2 (default ~/.gradle). The cache avoids re-downloading the same dependency on every build, speeding things up and enabling offline reuse.
What is centralized repository management in Gradle, and where do you configure it?
basics
~10 sIt's declaring repositories once for the whole build inside settings.gradle.kts using dependencyResolutionManagement { repositories {} }, instead of repeating repositories {} in every project's build.gradle.kts.
What is repository content filtering in Gradle, and why would you use it?
basics
~10 sIt tells Gradle which repositories can or cannot supply which modules, using a content {} block with includeGroup/excludeGroup. This avoids pointless lookups and speeds up resolution.
How do you configure a private Maven repository in Gradle that requires a username and password, and where should those secrets actually live?
basics
~10 sDeclare the repo with a url and a credentials { username; password } block. Don't hardcode the secrets — read them from gradle.properties or environment variables instead.
What is a repository in Gradle, and how do you declare one so your dependencies can be resolved?
basics
~10 sA repository is a source Gradle downloads dependency artifacts and metadata from. You declare them in a repositories {} block, e.g. mavenCentral(), so Gradle knows where to look for the modules you depend on.
How do you actually trigger a registered artifact transform during resolution using an artifactView?
basics
~10 sResolve the configuration with an artifactView that requests the transform's to attribute, e.g. configurations.runtimeClasspath.get().incoming.artifactView { attributes.attribute(artifactType, "classes") }.artifacts. Requesting that attribute makes Gradle insert the transform.
What does it mean to register an artifact transform in Gradle, and what do `from` and `to` describe?
basics
~10 sYou call dependencies.registerTransform(MyTransform) { ... } and declare from.attribute(...) and to.attribute(...). Gradle uses those attributes to know which artifacts the transform can convert and what it produces.
How do you correctly produce derived files inside a TransformAction using TransformOutputs, and what rule governs where those files may live?
basics
~20 sCall outputs.file(name) or outputs.dir(name) to get a location, then write your derived content there. Outputs must be either the input artifact itself or a path under the directory Gradle gives you — never an arbitrary location.
What is a TransformAction in Gradle, and what are the two essential pieces you must implement when writing one?
basics
~10 sA TransformAction converts an input artifact into one or more derived output files. You implement the transform(outputs) method and mark the input file with @InputArtifact so Gradle injects it.
Where can artifact transforms be registered, and how do they become available to a project or an entire build?
basics
~20 sYou register transforms inside a project's dependencies { registerTransform(...) } block, usually from a plugin's apply. The registration is scoped to that project; to share, apply the plugin (or a convention/settings plugin) to every project that needs it.
What is checksum verification in Gradle's dependency verification, and what problem does it solve?
basics
~10 sGradle records an expected hash (e.g. sha256) for each downloaded artifact in verification-metadata.xml. On every build it re-hashes the file and fails if it differs, proving the artifact wasn't tampered with or swapped.
What is the verification-metadata.xml file in Gradle, where does it live, and what is its purpose?
basics
~10 sIt's an XML file at gradle/verification-metadata.xml that lists trusted checksums and/or signatures for every dependency and plugin Gradle resolves. When present and enabled, Gradle verifies each artifact against it before use.
What does PGP signature verification in Gradle's dependency verification feature actually verify, and how does it differ from a checksum?
basics
~10 sPGP verification checks that a dependency's .asc signature file was produced by a trusted publisher's private key, proving authenticity. A checksum only proves the bytes match a recorded hash, not who produced them.
Walk through the practical workflow for keeping verification-metadata.xml current as your project adds and upgrades dependencies over time. What goes wrong if you do it carelessly?
basics
~20 sWhen you change dependencies, re-run --write-verification-metadata to append new entries, review the diff in your PR, and commit it. If you skip this, the build fails with 'artifact not in verification metadata'. Regenerating blindly can silently trust tampered artifacts.
How do you initially generate Gradle's verification-metadata.xml file, and what does the --write-verification-metadata flag actually do during the build?
basics
~10 sRun the build with --write-verification-metadata <checksums>, e.g. ./gradlew build --write-verification-metadata sha256. Gradle resolves all dependencies and writes their computed checksums into gradle/verification-metadata.xml.