What is Gradle?
Gradle is a free and open source build tool which replaces XML based build scripts with an internal DSL. It is similar to Maven and Ant. Gradle is implemented using Groovy& Kotlin, and Gradle build scripts are actually groovy scripts. Groovy is a programming language that runs on the Java Virtual Machine (JVM).Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM).
What are the Gradle Core concepts?
Gradle has three core concepts: projects, tasks, and build scripts. These concepts are explained in the following:
A project is either something we build (e.g. a jar file) or do (deploy our application to production environment). A project consists of one or more tasks.
A task is an atomic unit work which is performed our build (e.g. compiling our project or running tests).
The build script is typically called build.gradle and is normally located in the root directory of the project you are building. When the gradle command is executed it looks in the directory which the command is executed in, for the build script to execute
What are the features of Gradle?
- It is free and open source tool
- Declarative builds and build-by-convention
- Language for dependency based programming
- Deep API
- Structure your build
- Gradle scales
- Multi project builds
- Build scripts are written in Groovy or Kotlin Programming languages
- The gradle wrapper
- Easy of migration
- The first build integration tool
- Many ways to manage your dependencies
Can you explain Gradle dependency management?
Gradle dependency management refers to how Gradle handles the dependencies of your project. A dependency is an external JAR file that your project needs in order to be compiled and executed. For instance, if your project is a Java app that stores data in a database, then your project might use Hibernate to make this task easier. Your project then depends on Hibernate.
Note that project dependencies are not the same as task dependencies. A task may depend on another task. This means that one tasks needs another task to be executed before the task itself can be executed. This has nothing to do with the external JAR file dependencies of your project. These are two different types of dependencies, and Gradle handles them separately.
Can you explain Gradle Java Plugin?
Java pug- in is determined that all the useful features that you need for any particular build like compiling Java code or creating documentations etc are added by means of Plugin. The Plugin extends the features of Gradle and you can customize it for each of your builds. The Java plugin basically adds Java compilation along with testing and bundling capabilities to the project. It is introduced in the way of a SourceSet which act as a group of source files complied and executed together. Plugins, can therefore, add new tasks; can create new domino and etc.
Can you explain Dependency Configuration?
A dependency configuration is group of dependencies used for a specific purpose by your project. For instance, some JAR files might only be needed when you compile your code (like an annotation pre-processor). Other JAR files might be needed when you run the project code, or when you run the unit tests for your project.
What are the pre-defined dependency configurations?
The Java plug-in provides a few pre-defined dependency configurations that can be usefulyou’re your project. These dependency configurations are:
compile
runtime
testCompile
testRuntime
What is Compile dependency configuration?
Compile dependency configuration is the dependencies required to compile the production source of the project
What is runtime dependency configuration?
The testRuntime dependency configuration should contain all the dependencies needed to run the unit tests for your project. By default the testRuntime dependency configuration also includes all dependencies from the compile, runtime and testCompile dependency configurations.
What is testCompile in dependency configuration?
The dependencies required to compile the test source of the project. By default, it includes compiled production classes and the compile time dependencies.
What is testRuntime in dependency configuration?
The testRuntime dependency configuration should contain all the dependencies needed to run the unit tests for your project. By default the testRuntime dependency configuration also includes all dependencies from the compile, runtime and testCompile dependency configurations.
Can you explain External Dependencies?
An external dependency is a type of dependency. This is a dependency on some files that is built outside the current build, and is stored in a repository of some kind, such as Maven central, corporate Maven or lvy repository, or a directory in the local file system.
The following code snippet is to define the external dependency. Use this code in build.gradle file.
dependencies {
compile group: ‘org.hibernate’, name: ‘hibernate-core’, version: ‘3.6.7.Final’
}
What is Publishing Artifacts?
Dependency configurations are also used to publish files. These published files are called artifacts. Usually, we use plug-ins to define artifacts.
What is repository?
A repository is a central file storage location. It is used by version control systems to store multiple versions of files. While a repository can be configured on a local machine for a single user, it is often stored on a server, which can be accessed by multiple users.
Why Gradle is more preferred compared to other build framework?
Gradle script is written using groovy that has syntax similar to java, so easy to understand. Besides, it also offers support for multi project builds
Which language needs to be used for creating the Plugin?
To create the plug-in in JVM language is advised. However, you are also advised to try it out making in the language of your choice depending on the requirement for creating the plug-ins of the Gradle
Can you define Gradle Motto?
The Gradle tool has chosen an idealistic slogan which makes the user believe in a composite framework and the quote says “Make the impossible possible, make the possible easy, and make the easy elegant”.
What is the difference between Maven Build.xml and Build.gradle Script?
The two basic and important attributes are needed to define the Maven Build.xml this include the start tags and the end tags. On the other hand, Build.gradle runs on the programming language Groovy and this build script works on syntax.
What is the difference between the gradle.properties and settings.gradle?
This type of option is a groovy script which helps in defining the build associated settings. It is not related to any kind of project rather is an evaluation made against the object setting. You can also add further more projects in it. Through this it becomes possible for you to make the changes, modify the parameter and access the object of the Gradle in the convenient manner
How to create an IntelliJ Idea Gradle Project?
To start a Gradle Project in IntelliJ you need to first create a new project on this particular software and there you will get a number of options and out of which you will choose the Gradle options and next it will lead to a check-box where it shows all the empty directories like source main Java or source test Java and then we will choose a build Gradle wrapper to carry out the work process and will change the JVM version to 1.8. It eventually shows the all the skeleton of the project.
Can you explain Why use Gradle instead of Ant and Maven?
Both Ant and Maven work perfectly as a build tool and both has more or less similar features and traits. Ant is obliviously a flexible usage tool and Maven is known for its dependency efficiency management. But the unique features of Gradle tool make it gloriously significant than any other popular tool as it work remarkably on various multi-projects with hassle-free functions. Thus, Gradle has both the key features of both Ant and Maven
How is Daemon in Gradle 3.0?
- Better UX
- More powerful and sturdy
- Resource-aware
- Integrated with Gradle Build Scans
- Enabled By default
Can you explain Gradle Deployment?
The build artifacts repositories can be deployed by the Gradle tool in many ways it can easily change from Gradle to Maven by using the Maven-Publish Plugin.
What are the repository types in gradle?
- Flat directory repository
- Maven Central repository
- JCenter Maven repository
- Google Maven repository
- Local Maven repository
- Custom Maven repositories
- Custom Ivy repositories
- Supported metadata sources
- Supported repository transport protocols