Gradle Basics Quiz

BUILD & TOOLING › Gradle

A library module uses Retrofit only inside its own classes and never exposes Retrofit types in its public API. Which configuration should declare Retrofit?

Answer: implementation, keeping Retrofit an internal, non-transitive detail

Because Retrofit is an internal detail not exposed in the public API, implementation keeps it off consumers' compile classpath and avoids unnecessary recompilation when it changes.

Module A declares 'api("com.example:widgets:1.0")'. Module B depends on Module A with implementation. What can Module B do?

Answer: Reference com.example.widgets types directly on the compile classpath

api exposes the dependency transitively, so Module A's consumers, including Module B, get com.example:widgets on their compile classpath and can reference its types directly.

Which statement about compileOnly is correct?

Answer: It sits on the compile classpath only and is not packaged in the APK

compileOnly puts the library on the compile classpath but not the runtime classpath, so it is not packaged into the APK; it is meant for things like annotations or runtime-provided libraries.

In a version catalog, the library alias is written as 'androidx-core-ktx'. What accessor do you use in build.gradle.kts?

Answer: libs.androidx.core.ktx

Gradle maps dashes (or underscores) in catalog aliases to dots in the generated type-safe accessor, so androidx-core-ktx becomes libs.androidx.core.ktx.

What is the recommended default file and location for a Gradle version catalog in an Android project?

Answer: gradle/libs.versions.toml in the root project's gradle/ folder

Gradle looks for the catalog at gradle/libs.versions.toml by default, and using that name and location enables automatic type-safe accessors with no extra configuration.

How should you apply a plugin that is declared in the version catalog, in a module build.gradle.kts?

Answer: alias(libs.plugins.android.application)

Plugins that come from the catalog are applied with alias(libs.plugins...); id("...") is reserved for plugins not declared in the catalog, such as convention plugins.

What does Gradle's configuration cache primarily speed up?

Answer: Skipping re-run of the config phase when the build config is unchanged

The configuration cache stores the result of the configuration phase so Gradle can skip re-running build scripts on subsequent builds; reusing task outputs across machines is the separate build cache.

What is a key advantage of writing build files in the Kotlin DSL (build.gradle.kts) over the Groovy DSL (build.gradle)?

Answer: It provides type-safe syntax, autocomplete, and compile-time checks.

The Kotlin DSL is statically typed, so Android Studio offers autocomplete and catches errors at edit/compile time; both DSLs build identical artifacts and both support version catalogs.

What is the primary responsibility of settings.gradle.kts?

Answer: Including modules in the build and setting plugin/dependency repos

settings.gradle.kts uses include to register modules and configures pluginManagement and dependencyResolutionManagement repositories; dependencies live in module build files and JVM/cache flags live in gradle.properties.

You want JUnit available only to your local JVM unit tests in src/test, not to instrumented tests or the shipped app. Which configuration should declare it?

Answer: testImplementation

testImplementation scopes a dependency to the src/test (local JVM unit test) source set only, so it is excluded from the production app and from the src/androidTest instrumented source set.

Which configuration places a dependency on the runtime classpath but not the compile classpath?

Answer: runtimeOnly

runtimeOnly makes a dependency available at runtime and packages it, but it is not on the compile classpath; compileOnly is the exact opposite, while implementation and api put the dependency on both classpaths.

In the top-level build.gradle.kts you write id("com.android.application") version "8.x" apply false. What does apply false accomplish?

Answer: It pins the plugin version for subprojects, without applying it to the root

apply false declares the plugin and locks its version so module build files can apply it without repeating the version, while keeping it unapplied to the root project, which has no Android code to build.

What does a [bundles] entry in gradle/libs.versions.toml let you do?

Answer: Add several library aliases at once via one type-safe accessor

A bundle groups several library aliases under one name, so a module can add them all with a single accessor like libs.bundles.compose instead of listing each dependency individually.

Which statement correctly describes Gradle's build cache, as distinct from the configuration cache?

Answer: It reuses task outputs across builds and machines when inputs match

The build cache keys task outputs by their inputs and can reuse them locally or remotely across machines; caching the configuration phase is the separate configuration cache, and artifact downloads use Gradle's dependency cache.

Back to Gradle Basics