Gradle Flashcards
Learn gradle for interview
What is Gradle and how does it fit into the context of a Developer Productivity Engineer at Starling?
Gradle is a build automation tool that is widely used for Java projects. As a Developer Productivity Engineer at Starling, understanding Gradle is essential as it plays a crucial role in managing the build process and dependencies of the local development environment used by engineers.
Can you explain the basic structure of a Gradle build file?
A Gradle build file typically consists of a set of tasks and dependencies defined in a Groovy or Kotlin DSL. It includes sections for configuring plugins, defining dependencies, and specifying tasks to be executed during the build process.
How do you define dependencies in a Gradle build file?
A Gradle build file typically consists of a set of tasks and dependencies defined in a Groovy or Kotlin DSL. It includes sections for configuring plugins, defining dependencies, and specifying tasks to be executed during the build process.
What is the purpose of the repositories block in a Gradle build file?
The repositories block in a Gradle build file is used to specify the locations from which Gradle should retrieve dependencies. These repositories can be local directories, remote Maven or Ivy repositories, or other sources.
How does Gradle handle transitive dependencies?
Gradle automatically resolves and includes transitive dependencies, which are dependencies required by other dependencies. This helps simplify dependency management by allowing you to declare only direct dependencies in your build file.
What are Gradle plugins, and how are they used?
Gradle plugins are reusable pieces of functionality that can be applied to a project to extend or customize its build process. They are typically configured in the plugins block of the build file and provide additional tasks, conventions, or behaviors.
How can you create custom tasks in Gradle?
Custom tasks in Gradle are defined by extending the org.gradle.api.DefaultTask class and implementing the desired functionality. These tasks can then be configured and added to the build process like built-in tasks.
What is the purpose of the gradle.properties file?
The gradle.properties file allows you to define project-wide properties and configuration settings for Gradle builds. These properties can be referenced in the build script to parameterize tasks and settings.
How does Gradle handle incremental builds?
Gradle optimizes build times by performing incremental builds, which means it only executes tasks that have changed inputs or outputs since the last build. This helps speed up the build process, especially for large projects.
What is the difference between compile, implementation, and api dependencies in Gradle?
in earlier versions of Gradle, compile was used to include dependencies for both compiling and runtime, implementation is used for dependencies that should be internal to the module, and api is used for dependencies that are exposed to consumers.
How can you exclude certain transitive dependencies in Gradle?
You can exclude transitive dependencies by using the exclude keyword within the dependency declaration. This allows you to specify specific dependencies to be excluded from the resolution process.
What is a Gradle wrapper, and why is it useful?
The Gradle wrapper is a script (gradlew or gradlew.bat) that allows you to run Gradle builds without requiring a local installation of Gradle. It ensures that the correct version of Gradle is used for the project, making builds more reproducible and consistent across environments.
how can you configure multiple build flavors or variants in Gradle?
Gradle allows you to define product flavors and build variants using the android or java plugin. This enables you to create different versions of your application or library with varying configurations or features.
What is the purpose of the settings.gradle file in a Gradle project?
The settings.gradle file is used to configure settings for a Gradle multi-project build. It specifies the structure of the project hierarchy and defines which subprojects are included in the build.
How can you profile and optimize Gradle builds for performance?
Gradle provides tools like the –profile option and build scans to analyze and optimize build performance. Techniques such as parallel execution, caching, and dependency optimization can be applied to improve build times.