Gradle Interview Questions
What is Gradle build tool?
Gradle is a build automation tool based on Groovy and Kotlin. It’s open-source and flexible enough to build almost any type of software. It also supports both the automatic download of dependencies and many repositories, including Maven and Ivy.
Is Gradle a framework?
Gradle is a build automation tool for multi-language software development. … Gradle builds on the concepts of Apache Ant and Apache Maven, and introduces a Groovy- & Kotlin-based domain-specific language contrasted with the XML-based project configuration used by Maven.
What is DSL in Gradle?
Simply, it stands for ‘Domain-Specific Language’. IMO, in Gradle context, DSL gives you a gradle specific way to form your build scripts. More precisely, it’s a plugin-based build system that defines a way of setting up your build script using (mainly) building blocks defined in various plugins.
What is closure in Gradle?
Note in Gradle DSL, closures are frequently (and idiomatically) used as the last method parameter to configure some object. This is a pattern called configuration closure. … Gradle uses this for configuration closures, where the delegate object is set to the object to be configured.
What is assemble in Gradle?
Assemble will build your artifacts, and build will assemble your artifacts with additional checks. Build depends on assemble, so build is sort of a superset of assemble. You can have a look on the tasks that will be executed by using the –dry-run flag. e.g. gradlew build –dry-run.
Is Gradle only for Java?
Gradle runs on the JVM and you must have a Java Development Kit (JDK) installed to use it. … Several major IDEs allow you to import Gradle builds and interact with them: Android Studio, IntelliJ IDEA, Eclipse, and NetBeans.
What is EXT in build gradle?
ext is shorthand for project. ext , and is used to define extra properties for the project object. (It’s also possible to define extra properties for many other objects.) When reading an extra property, the ext. is omitted (e.g. println project.
What is apply from in Gradle?
The actual difference between apply from: and apply plugin: is that the former is to be used for script plugins given a path to the local file system or a URL to a remote location, and the latter is used for binary plugins using the plugin id.
11 . The main difference between Maven build.xml and Build.gradle script?
Maven build.xml is xml document that includes start and end tags. Build.gradle is a Groovy script which has syntax similar to Java.
12 . How do I force Gradle to download dependencies always?
You may refresh dependencies in your cache using the command line option –refresh-dependencies. Also deleting the cached files under ~/.gradle/caches would get the next Gradle build to download them again.
13 . What is the Gradle project and task?
- Every Gradle build is made up of one or more projects. What a project represents depends on what it is that you are doing with Gradle.
- For example, a project might represent a library JAR or a web application. It might represent a distribution ZIP assembled from the JARs produced by other projects.
- A project does not necessarily represent a thing to be built. It might represent a thing to be done, such as deploying your application to staging or production environments.
- Don’t worry if this seems a little vague for now. Gradle’s build-by-convention support adds a more concrete definition of what a project is.
- Each project is made up of one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.
14 . Create a Gradle task and explain how to execute it?
The Gradle build file defines the project and its tasks. The below list a simple task to print “Hello world!”.
task hello {
doLast {
println ‘Hello World!’
}
}
Run Gradle hello on the command line in the directory of the build file to execute hello task. If the Gradle output should be suppressed, use the -q (quiet) parameter.
gradle hello
15 . What is Gradle Daemon?
The Daemon is a long-lived process that helps with the faster build process, by avoiding the cost of JVM startup for every build and also caches information about project structure, files, tasks, and more in memory.
16 . How Gradle achieves faster performance?
Gradle improves build speed by reusing computations from previous builds and also uses cache information.
17 . Difference between settings.gradle & gradle.properties?
The settings.gradle is a Groovy script that defines build related settings and not project related. It is evaluated against a Settings object and with this Settings object, you can add sub projects to your build, modify the parameter from the command line (StartParameter) and access the Gradle object to register lifecycle handlers.
The gradle.properties file is a simple Java Properties file. It’s a simple key-value store, that only allows string values.
18 . List the gradle build configuration files?
Ans:
- build.gradle, script that defines the build configuration,
- gradle.properties,
- and settings.gradle.
19 . How do I add gradle dependencies?
To add a dependency to your project, specify a dependency configuration such as compile under the dependencies block of your build.gradle file.
dependencies {
compile group: ‘org.hibernate’, name: ‘hibernate-core’, version: ‘3.6.7.Final’
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.+’
}
20 . What is the Gradle command to view the list of available projects?
Use gradle projects command.
For more Click Here