Skip to content

Interview questions

A collection of technical interview questions covering Gradle, JVM, Kotlin, Java, and Android internals to help you prepare for developer interviews.

What is Gradle JDK?

For building the application, we use the build system Gradle.

Gradle runs inside its own JVM (launched by gradlew).

Gradle JDK is the JDK used for these tasks.

The application build can be done in two ways:

  1. Using the built-in features of Android Studio (AS) – in this case, the Gradle JDK is the one specified in the AS settings.
  2. Using the CLI – in this case, the JDK is selected by the gradlew script: from JAVA_HOME or, if it is not set, the system default JDK, which can be found by the command /usr/libexec/java_home -V.

If the build is done using both methods and Gradle chooses different JDKs, multiple java processes are created. Therefore, it is recommended to configure the same Gradle JDK for both cases.

What is gradle/wrapper/gradle-wrapper.jar?

gradle-wrapper.jar is a precompiled set of classes from:

  1. /platforms/core-runtime/cli/src/main/java/org/gradle/cli
  2. /platforms/core-runtime/wrapper-main/src/main/java/org/gradle/wrapper
  3. /platforms/core-runtime/wrapper-shared/src/main/java/org/gradle/wrapper
  4. /platforms/core-runtime/wrapper-shared/src/main/java/org/gradle/internal/file/locking

It is used to download the Gradle version specified in gradle-wrapper.properties into the .gradle directory and serves as the entry point to launch GradleMain — i.e., essentially runs gradle with the given arguments.

What is gradle/wrapper/gradle-wrapper.properties?

This file is used to configure:

  1. The Gradle version to use (in distributionUrl)
  2. Parameters for downloading the Gradle distribution

What are gradlew / gradlew.bat?

These are scripts for *nix and Windows systems, respectively. They are used to work with the Gradle wrapper: they obtain the required Gradle JDK, set the gradle-wrapper.jar as the executable via the -classpath parameter for java, and set the entry point as org.gradle.wrapper.GradleWrapperMain.

What is gradle.properties in the project root?

This file contains system properties passed to gradlew and then to gradle and java (saved in the method addSystemProperties in the GradleWrapperMain class).

What Java processes may be launched during the build?

  1. Gradle JVM
  2. Kotlin Compiler

What is a transitive dependency?

A transitive dependency is a dependency that is automatically included in the project through another dependency that was directly added.

You can inspect dependencies by running gradle buildEnvironment.

Transitive dependencies used by multiple other dependencies are marked with * in the dependency tree output:

(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees
only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.

Explain what sources.jar and classes.jar are?

sources.jar is a .jar archive containing the raw (uncompiled) source files.

classes.jar is a .jar archive containing the compiled class files of the source code.

When adding a library as a dependency, the artifact may provide both classes.jar and sources.jar.
Android Studio (AS) (how?) also downloads the sources.jar when the dependency is declared in the dependencies block to allow convenient viewing of the library's source code for debugging purposes.

Why when adding a plugin to a project via plugins {} only its plugin.id and plugin.version are used?

Actually, Gradle uses the following notation to find the required artifact in repositories:
plugin.id:plugin.id.gradle.plugin:plugin.version.

When developing a plugin, .gradle.plugin is not explicitly specified but added automatically when using the plugin creation task from java-gradle-plugin.

Which JDK is used when starting Gradle?

  1. java.home property in .gradle/config.properties
  2. Environment variable JAVA_HOME
  3. The default JDK used by the system when running java --version

Comments