Browse [LATEST] Gradle Interview Questions & Answer [ 2020 ]
Gradle Interview Questions and Answers

Browse [LATEST] Gradle Interview Questions & Answer

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Madhusudhan (Lead Engineer - Director Level )

(5.0) | 16547 Ratings 679
  • Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing.
  • The methodology of Gradle builds on the concepts of Apache Ant and Apache Maven, and introduces a Groovy-based domain-specific language, rather than using of the XML form used by Maven for declaring the project configuration.
  • Gradle uses a directed acyclic graph to determine the order in which tasks can be run, through providing dependency management.
  • Gradle was designed for multi-project builds, which can grow to be large. It operates based on a series of build tasks that can run serially or in parallel. Incremental builds are supported by determining the parts of the build tree that are already up to date; any task dependent only on those parts does not need to be re-executed.
  • It also supports caching of build components, potentially across a shared network. It produces web-based build visualization. The software is extensible for new features and programming languages with a plugin subsystem.

FREQUENTLY ASKED INTERVIEW QUESTIONS AND ANSWERS:

1. What is the Gradle framework?

Ans:

Gradle is an open source build automation system that builds based on the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.

2 . Advantages of using Gradle?

Ans:

Gradle combines both Ant and Maven, taking the best from both of these frameworks; Flexibility from Ant tool and convention over configuration, dependency management and plugins from Maven.

3 . Gradle provides support for multi-project builds?

Ans:

It allows users to use existing Maven/Ivy repositories.

Free and open source.

Scalable nature.

4 . What is a Gradle wrapper?

Ans:

A wrapper is a batch script and it is one of the ways to perform Gradle build. When executed the first time, it automatically downloads Gradle and then initiates the build.

It helps to set up Gradle workspace quickly for first-time users (Zero installation) and also ensures all the developers use the same version of Gradle.

5 . Why is Gradle preferred over other build tools?

Ans:

Gradle build script is written using a groovy API which has the syntax similar to Java so it is easy to understand.

  • Gradle supports ant tasks, ivy and Maven repositories for dependency management. It also has a maven Pom.xml converter to Gradle build script.
  • It is open source.
  • provides strong support for multi project builds.
  • supports build cache.

6 . What is the Gradle build script file name?

Ans:

build.gradle.

7 . What is the latest version of Gradle available in the market?

Ans:

Gradle build tool latest version is 3.5 as of May 2017. The version on your local Gradle installation can be checked using gradle -v command.

8 . How do you run Gradle build?

Ans:

Execute Gradle build using gradle command.

9 . What are the core components of Gradle build script?

Ans:

Project and task are the core components. Groovy organizes projects as a list of tasks. To view the list of available projects, use the command gradle projects, for the tasks list the command is gradle tasks.

10 . How do you find Gradle project dependencies?

Ans:

Use the Gradle command gradle dependencies that lists the dependencies of the selected project. It includes both direct and transitive dependencies.

11 . The main difference between Maven build.xml and Build.gradle script?

Ans:

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?

Ans:

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?

Ans:

  • 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.

Ans:

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?

Ans:

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?

Ans:

Gradle improves build speed by reusing computations from previous builds and also uses cache information.

17 . Difference between settings.gradle & gradle.properties.

Ans:

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?

Ans:

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?

Ans:

Use gradle projects command.

    Subscribe For Free Demo

    21 . Types of plugin in Gradle.

    Ans:

    There are 2 general types of plugins in Gradle, script plugins and binary plugins.

    • Script plugins are additional build scripts that further configure the build and usually implement a declarative approach to manipulating the build.
    • Binary plugins are classes that implement the Plugin interface and adopt a programmatic approach to manipulating the build.

    22 . In which programming language should one develop plugins for Gradle?

    Ans:

    One can develop plugins for Gradle in any JVM language such as Java, Scala etc.

    23 . Explain spring boot gradle plugin.

    Ans:

    The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, allowing you to package executable jar or war, execute Spring Boot applications, and use the dependency management provided by spring-boot-dependencies.

    24 . What is a Gradle build language?

    Ans:

    Gradle provides a domain specific language (DSL) for describing builds. This build language is available in Groovy and Kotlin.

    25 . Default file name of the Groovy build script?

    Ans:

    It is build.gradle. Kotlin DSL script files use the .gradle.kts file name extension.

    26 . What are all projects and subprojects sections in the Gradle build file?

    Ans:

    A multi-project gradle build will have rootProject and the subprojects, both together, are considered as allprojects. The build starts from rootProject however it usually has no code, subproject does. allproject section can have dependencies seen by all projects while subproject dependencies seen only by those sub projects.

    Usually subprojects only apply to the Java plugin as it has code.

    • subprojects {
    •     apply plugin: ‘java’

    27 . How do I find the Gradle version?

    Ans:

    Open a console (or a Windows command prompt) and run gradle -v to run gradle and display the version as shown in the below picture.

    28 . What are the features of the Spring Boot Gradle Plugin?

    Ans:

    The Spring Boot Gradle Plugin provides Spring Boot support in Gradle. It collects all the jars on the classpath and builds a single, runnable jar, which makes it more convenient to execute and transport your service.

    • plugins {
    • id ‘org.springframework.boot’ version ‘2.2.1.RELEASE’
    • }

    Difference between declaring repositories in the buildScript section of the Gradle build or in the root level of the build.

    • buildScript {
    •     repositories {
    •         mavenCentral()
    •     }
    • }

    The repositories in the buildScript block are used to fetch the dependencies of your buildScript dependencies. For example, your plugin dependencies are listed here.

    • repositories {
    •     mavenCentral()
    • }

    The repositories on the root level are used to fetch the dependencies that your project depends on. So all the dependencies you need to compile your project.

    29 . Difference between api and implementation in Gradle?

    Ans:

    The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

    • dependencies {
    •     api ‘org.apache.httpcomponents:httpclient:4.5.7’
    •     implementation ‘org.apache.commons:commons-lang3:3.5’
    • }

    Dependencies appearing in the “api” configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers. Dependencies found in the “implementation” configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers’ compile classpath.

    30 . Why Gradle Is Preferred Over Maven or Ant?

    Ans:

    There isn’t a great support for multi-project builds in Ant and Maven. Developers end up doing a lot of coding to support multi-project builds.

    • Also having some build-by-convention is nice and makes build scripts more concise. With Maven, it takes build by convention too far, and customizing your build process becomes a hack.
    • Maven also promotes every project publishing an artifact. Maven does not support subprojects to be built and versioned together.
    • But with Gradle developers can have the flexibility of Ant and build by convention of Maven.
    • Groovy is easier and clean to code than XML. In Gradle, developers can define dependencies between projects on the local file system without the need to publish artifacts to repository.
    Course Curriculum

    Learn Gradle Training & Certification Course By Experts Trainers

    Weekday / Weekend BatchesSee Batch Details

    31 . Gradle Vs Maven

    Ans:

    The following is a summary of the major differences between Gradle and Apache Maven:

    • Flexibility: Google chose Gradle as the official build tool for Android; not because build scripts are code, but because Gradle is modeled in a way that is extensible in the most fundamental ways.
    • Both Gradle and Maven provide convention over configuration. However, Maven provides a very rigid model that makes customization tedious and sometimes impossible.
    • While this can make it easier to understand any given Maven build, it also makes it unsuitable for many automation problems. Gradle, on the other hand, is built with an empowered and responsible user in mind.
    • Performance: Both Gradle and Maven employ some form of parallel project building and parallel dependency resolution. The biggest differences are Gradle’s mechanisms for work avoidance and incrementally. Following features make Gradle much faster than Maven:
    • Incrementally: Gradle avoids work by tracking input and output of tasks and only running what is necessary. 
    • Build Cache: Reuses the build outputs of any other Gradle build with the same inputs.
    • Gradle Daemon: A long-lived process that keeps build information “hot” in memory.
    • User Experience: Maven’s has a very good support for various IDE’s. Gradle’s IDE support continues to improve quickly but is not great as of Maven.

    32 . What are Gradle Build Scripts?

    Ans:

    Gradle builds a script file for handling projects and tasks. Every Gradle build represents one or more projects. A project represents a library JAR or a web application.

    33 . What is Gradle Wrapper?

    Ans:

    The wrapper is a batch script on Windows, and a shell script for other operating systems. Gradle Wrapper is the preferred way of starting a Gradle build. When a Gradle build is started via the wrapper, Gradle will automatically download and run the build.

    34 . What is Gradle Build Script File Name?

    Ans:

    This type of name is written in the format that is build.gradle. It generally configures the Gradle scripting language.

    35 . How To Add Dependencies In Gradle?

    Ans:

    In order to make sure that dependency for your project is added, you need to mention the configuration dependency like compiling the block dependencies of the build.gradle file.

    36 . What Is Dependency Configuration?

    Ans:

    Dependency configuration comprises the external dependency, which you need to install well and make sure the downloading is done from the web. There are some key features of this configuration which are:

    • Compilation: The project which you would be starting and working on the first needs to be well compiled and ensure that it is maintained in the good condition.
    • Runtime: It is the desired time which is required to get the work dependency in the form of collection.
    • Test Compile: The dependencies check source requires the collection to be made for running the project.
    • Test runtime: This is the final process which needs the checking to be done for running the test that is in a default manner considered to be the mode of runtime

    37 . What Is Dependency Management in Gradle?

    Ans:

    • Software projects rarely work in isolation. In most cases, a project relies on reusable functionality in the form of libraries or is broken up into individual components to compose a modularized system.
    • Dependency management is a technique for declaring, resolving and using dependencies required by the project in an automated fashion.
    • Gradle has built-in support for dependency management and lives up the task of fulfilling typical scenarios encountered in modern software projects.

    38 . What Are Benefits Of Daemon in Gradle 3.0

    Ans:

    Here are some of the benefits of Gradle daemon

    • It has good UX
    • It is very powerful
    • It is aware of the resource
    • It is well integrated with the Gradle Build scans
    • It has been default enabled

    39 . What Is Gradle Multi-Project Build?

    Ans:

    • Multi-project builds help with modularization. It allows a person to concentrate on one area of work in a larger project, while Gradle takes care of dependencies from other parts of the project
    • A multi-project build in Gradle consists of one root project, and one or more subprojects that may also have subprojects.
    • While each subproject could configure itself in complete isolation of the other subprojects, it is common that subprojects share common traits.
    • It is then usually preferable to share configurations among projects, so the same configuration affects several subprojects.

    40 . What Is the Gradle Build Task?

    Ans:

    Gradle Build Tasks is made up of one or more projects and a project represents what has been done with Gradle.

    Some key of features of Gradle Build Tasks are:

    • Task has lifecycle methods [do first, do last]
    • Build Scripts are code
    • Default tasks like run, clean etc
    • Task dependencies can be defined using properties like dependsOn

    41 . What is the Gradle Build Life Cycle?

    Ans:

    Gradle Build lifecycle consists of following three steps

    • Initialization phase: In this phase the project layer or objects are organized
    • Configuration phase: In this phase all the tasks are available for the current build and a dependency graph is created
    • Execution phase: In this phase tasks are executed.

    42 . What is Gradle Java Plugin?

    Ans:

    The Java plugin 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 compiled and executed together.

    43 . Why Groovy Is Gaining Popularity?

    Ans:

    Here are few reasons for popularity of Groovy:

    • Familiar OOP language syntax.
    • Extensive stock of various Java libraries
    • Increased expressivity (type less to do more)
    • Dynamic typing (lets you code more quickly, at least initially)
    • Closures
    • Native associative array/key-value mapping support (you can create an associative array literal)
    • String interpolation (cleaner creation of strings displaying values)
    • Regex’s being first class citizens

    44 . What Is Meant By Thin Documentation In Groovy

    Ans:

    • Groovy is documented very badly. In fact the core documentation of Groovy is limited and there is no information regarding the complex and run-time errors that happen.
    • Developers are largely on  there own and they normally have to figure out the explanations about internal workings by themselves.

    45 . How To Run Shell Commands in Groovy?

    Ans:

    Groovy adds the execute method to String to make executing shells fairly easy

    println “ls”.execute().text

    46 . Can Groovy Integrate With Non Java Based Languages?

    Ans:

    It is possible but in this case the features are limited. Groovy cannot be made to handle all the tasks in a manner it has to.

    47 . What are Pre-Requirements For Groovy?

    Ans:

    • Installing and using Groovy is easy. Groovy does not have complex system requirements. It is OS independent.
    • Groovy can perform optimally in every situation.There are many Java based components in Groovy,which make it even more easier to work with Java applications.

    48 . What Is Closure In Groovy?

    Ans:

    • A closure in Groovy is an open, anonymous, block of code that can take arguments, return a value and be assigned to a variable.
    • A closure may reference variables declared in its surrounding scope.
    • In opposition to the formal definition of a closure, Closure in the Groovy language can also contain free variables which are defined outside of its surrounding scope. 
    • A closure definition follows this syntax:

    { [closureParameters -> ] statements }

    • Where [closureParameters->] is an optional comma-delimited list of parameters, and statements are 0 or more Groovy statements. The parameters look similar to a method parameter list, and these parameters may be typed or untyped.
    • When a parameter list is specified, the -> character is required and serves to separate the arguments from the closure body. The statements portion consists of 0, 1, or many Groovy statements.

    49 . What is ExpandoMeta Class In Groovy?

    Ans:

    • Through this class programmers can add properties, constructors, methods and operations in the task. It is a powerful option available in the Groovy.
    • By default this class cannot be inherited and users need to call explicitly. The command for this is “ExpandoMetaClass.enableGlobally()”.

    50 . What Are Limitations Of Groovy?

    Ans:

    Groovy has some limitations. They are described below

    • It can be slower than the other object-oriented programming languages.
    • It might need memory more than that required by other languages.
    • The start-up time of groovy requires improvement. It is not that frequent.
    • For using groovy, you need to have enough knowledge of Java. Knowledge of Java is important because half of groovy is based on Java.
    • It might take you some time to get used to the usual syntax and default typing.
    • It consists of thin documentation.
    Course Curriculum

    Get Practical Oriented Gradle Training to UPGRADE Your Skill Set

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    51 . How To Write HelloWorld Program In Groovy

    Ans:

    The following is a basic Hello World program written in Groovy:

    • class Test {
    • static void main(String[] args) {
    • println(‘Hello World’);
    • }
    • }

    52 . How To Declare String In Groovy?

    Ans:

    In Groovy, the following steps are needed to declare a string.

    • The string is closed with single and double qotes.
    • It contains Groovy Expressions noted in ${}
    • Square bracket syntax may be applied like charAt(i)

    53 . Differences Between Java And Groovy?

    Ans:

    • Groovy tries to be as natural as possible for Java developers. Here are all the major differences between Java and Groovy.

    -Default imports

    • In Groovy all these packages and classes are imported by default, i.e. Developers  do not have to use an explicit import statement to use them:
    • java.io.*
    • java.lang.*
    • java.math.BigDecimal
    • java.math.BigInteger
    • java.net.*
    • java.util.*
    • groovy.lang.*
    • groovy.util.*

    -Multi-methods

    • In Groovy, the methods which will be invoked are chosen at runtime. This is called runtime dispatch or multi-methods. It means that the method will be chosen based on the types of the arguments at runtime. In Java, this is the opposite: methods are chosen at compile time, based on the declared types.

    -Array initializers

    • In Groovy, the { … } block is reserved for closures. That means that you cannot create array literals with this syntax:
    • int[] arraySyntex = { 6, 3, 1}

    You actually have to use:

    • int[] arraySyntex = [1,2,3]

    -ARM blocks

    • ARM (Automatic Resource Management) block from Java 7 are not supported in Groovy. Instead, Groovy provides various methods relying on closures, which have the same effect while being more idiomatic. 

    -GStrings

    • As double-quoted string literals are interpreted as GString values, Groovy may fail with compile error or produce subtly different code if a class with String literal containing a dollar character is compiled with Groovy and Java compiler.
    • While typically, Groovy will auto-cast between GString and String if an API declares the type of a parameter, beware of Java APIs that accept an Object parameter and then check the actual type.

    -String and Character literals

    • Singly-quoted literals in Groovy are used for String, and double-quoted result in String or GString, depending whether there is interpolation in the literal.
    • assert ‘c’.getClass()==String
    • assert “c”.getClass()==String
    • assert “c${1}”.getClass() in GString
    • Groovy will automatically cast a single-character String to char only when assigning to a variable of type char. When calling methods with arguments of type char we need to either cast explicitly or make sure the value has been cast in advance.
    • char a=’a’
    • assert Character.digit(a, 16)==10 : ‘But Groovy does boxing’
    • assert Character.digit((char) ‘a’, 16)==10
    • try {
    •   assert Character.digit(‘a’, 16)==10
    •   assert false: ‘Need explicit cast’
    • } catch(MissingMethodException e) {
    • }
    • Groovy supports two styles of casting and in the case of casting to char there are subtle differences when casting a multi-char strings. The Groovy style cast is more lenient and will take the first character, while the C-style cast will fail with exception.

    // for single char strings, both are the same

    • assert ((char) “c”).class==Character
    • assert (“c” as char).class==Character
    • // for multi char strings they are not
    • try {
    •   ((char) ‘cx’) == ‘c’
    •   assert false: ‘will fail – not castable’
    • } catch(GroovyCastException e) {
    • }
    • assert (‘cx’ as char) == ‘c’
    • assert ‘cx’.asType(char) == ‘c’

    -Behaviour of ==

    • In Java == means equality of primitive types or identity for objects. In Groovy == translates to a.compareTo(b)==0, if they are Comparable, and a.equals(b) otherwise. To check for identity, there is is. E.g. a.is(b).

    54 . How To Test Groovy Application?

    Ans:

    • The Groovy programming language comes with great support for writing tests. In addition to the language features and test integration with state-of-the-art testing libraries and frameworks.
    • The Groovy ecosystem has born a rich set of testing libraries and frameworks.
    • Groovy Provides following testing capabilities

    Junit Integrations

    Spock for specifications

    Geb for Functional Test

    • Groovy also  has excellent built-in support for a range of mocking and stubbing alternatives. When using Java, dynamic mocking frameworks are very popular.
    • A key reason for this is that it is hard work creating custom hand-crafted mocks using Java. Such frameworks can be used easily with Groovy.

    55 . What Are Power Assertions In Groovy?

    Ans:

    • Writing tests means formulating assumptions by using assertions. In Java this can be done by using the assertkeyword. But Groovy comes with a powerful variant of assert also known as power assertion statement.
    • Groovy’s power assert differs from the Java version in its output given the boolean expression validates to false:
    • def x = 1
    • assert x == 2

     

    • // Output:             
    • //
    • // Assertion failed:
    • // assert x == 2
    • //        | |
    • //        1 false

    This section shows the std-err output

    • The java.lang.AssertionError that is thrown whenever the assertion can not be validated successfully, contains an extended version of the original exception message. The power assertion output shows evaluation results from the outer to the inner expression.
    • The power assertion statements true power unleashes in complex Boolean statements, or statements with collections or other toString-enabled classes:
    • def x = [1,2,3,4,5]
    • assert (x << 6) == [6,7,8,9,10]
    • // Output:
    • //
    • // Assertion failed:
    • // assert (x << 6) == [6,7,8,9,10]
    • //         | |     |
    • //         | |     false
    • //         | [1, 2, 3, 4, 5, 6]
    • //         [1, 2, 3, 4, 5, 6]

    56 . Can We Use Design Patterns In Groovy?

    Ans:

    • Design patterns can also be used with Groovy. Here are important points .
    • Some patterns carry over directly (and can make use of normal Groovy syntax improvements for greater readability).
    • Some patterns are no longer required because they are built right into the language or because Groovy supports a better way of achieving the intent of the pattern.
    • Some patterns that have to be expressed at the design level in other languages can be implemented directly in Groovy (due to the way Groovy can blur the distinction between design and implementation).

    57 . How To Parse And Produce JSON Object In Groovy?

    Ans:

    • Groovy comes with integrated support for converting between Groovy objects and JSON. The classes dedicated to JSON serialisation and parsing are found in the groovy.json package.
    • JsonSlurper is a class that parses JSON text or reader content into Groovy data structures (objects) such as maps, lists and primitive types like Integer, Double, Boolean and String.
    • The class comes with a bunch of overloaded parse methods plus some special methods such as parseText,parseFile and others

    58 . What Is Difference Between XmlParser And XmlSluper?

    Ans:

    XmlParser and XmlSluper are used for parsing XML with Groovy. Both have the same approach to parse an xml. Both come with a bunch of overloaded parse methods plus some special methods such as parseText, parseFile and others.

    XmlSlurper

    • def text = ”’
    •     <list>
    •         <technology>
    •             <name>Groovy</name>
    •         </technology>
    •     </list>
    • ”’
    • def list = new XmlSlurper().parseText(text) 
    • assert list instanceof groovy.util.slurpersupport.GPathResult 
    • assert list.technology.name == ‘Groovy’ 

      Parsing the XML an returning the root node as a GPathResult

      Checking we’re using a GPathResult

      Traversing the tree in a GPath style

    XmlParser

    • def text = ”’
    •     <list>
    •         <technology>
    •             <name>Groovy</name>
    •         </technology>
    •     </list>
    • ”’
    • def list = new XmlParser().parseText(text) 
    • assert list instanceof groovy.util.Node 
    • assert list.technology.name.text() == ‘Groovy’ 

      Parsing the XML an returning the root node as a Node

      Checking we’re using a Node

      Traversing the tree in a GPath style

    59 . What is Maven?

    Ans:

    • Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software:
    • First: It describes how software is built
    • Second: It describes its dependencies.
    • Unlike earlier tools like Apache Ant, it uses conventions for the build procedure, and only exceptions need to be written down.

    An XML file describes the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins.

    • It comes with pre-defined targets for performing certain well-defined tasks such as compilation of code and its packaging.
    • Maven dynamically downloads Java libraries and Maven plug-ins from one or more repositories such as the Maven 2 Central Repository, and stores them in a local cache. 
    • This local cache of downloaded artifacts can also be updated with artifacts created by local projects. Public repositories can also be updated.

    60 . What Are Benefits Of Maven?

    Ans:

    • One of the biggest benefit of Maven is that its design regards all projects as having a certain structure and a set of supported task work-flows.
    • Maven has quick project setup, no complicated build.xml files, just a POM and go
    • All developers in a project use the same jar dependencies due to centralized POM.
    • In Maven getting a number of reports and metrics for a project “for free”
    • It reduces the size of source distributions, because jars can be pulled from a central location
    • Maven lets developers get your package dependencies easily
    • With Maven there is no need to add jar files manually to the class path

    61 . What Are Build Life cycles In Maven?

    Ans:

    • Build lifecycle is a list of named phases that can be used to give order to goal execution. One of Maven’s standard life cycles is the default lifecycle, which includes the following phases, in this order

     1  validate

     2  generate-sources

     3  process-sources

     4  generate-resources

     5  process-resources

     6  compile

     7  process-test-sources

     8  process-test-resources

     9  test-compile

    10  test

    11  package

    12  install

    13  deploy

    62 . What Is Meant By Build Tool?

    Ans:

    • Build tools are programs that automate the creation of executable applications from source code.
    • Building incorporates compiling, linking and packaging the code into a usable or executable form. In small projects, developers will often manually invoke the build process.
    • This is not practical for larger projects. Where it is very hard to keep track of what needs to be built, in what sequence and what dependencies there are in the building process.
    • Using an automation tool like Maven, Gradle or ANT allows the build process to be more consistent.

    63 . What Is Dependency Management Mechanism In Gradle?

    Ans:

    • Maven’s dependency-handling mechanism is organized around a coordinate system identifying individual artifacts such as software libraries or modules.
    • For example if a project needs  Hibernate library. It has to  simply declare Hibernate’s project coordinates in its POM.
    • Maven will automatically download the dependency and the dependencies that Hibernate itself needs and store them in the user’s local repository.
    • Maven 2 Central Repository is used by default to search for libraries, but developers can configure the custom repositories to be used (e.g., company-private repositories) within the POM.

    64 . What Is Central Repository Search Engine?

    Ans:

    The Central Repository Search Engine, can be used to find out coordinates for different open-source libraries and frameworks.

    65 . What are Plugins In Maven?

    Ans:

    • Most of Maven’s functionality is in plugins. A plugin provides a set of goals that can be executed using the following syntax:

     mvn [plugin-name]:[goal-name]

    • For example, a Java project can be compiled with the compiler-plugin’s compile-goal by running mvn compiler:compile.
    • There are Maven plugins for building, testing, source control management, running a web server, generating Eclipse project files, and much more.
    • Plugins are introduced and configured in a <plugins>-section of a pom.xml file. Some basic plugins are included in every project by default, and they have sensible default settings.

    66 . What Is Difference Between Maven And ANT?

    Ans:

    • Ant Maven
    • Ant is a tool box. Maven is a framework.
    • There is no life cycle. There is life cycle.
    • Ant doesn’t have formal conventions. Maven has a convention to place source code, compiled code etc.
    • Ant is procedural. Maven is declarative.
    • The ant scripts are not reusable. The maven plugins are reusable.

    67 . What is POM In Maven?

    Ans:

    • A Project Object Model (POM) provides all the configuration for a single project. General configuration covers the project’s name, its owner and its dependencies on other projects.
    • One can also configure individual phases of the build process, which are implemented as plugins.
    • For example, one can configure the compiler-plugin to use Java version 1.5 for compilation, or specify packaging the project even if some unit tests fail.
    • Larger projects should be divided into several modules, or sub-projects, each with its own POM. One can then write a root POM through which one can compile all the modules with a single command.
    • POMs can also inherit configuration from other POMs. All POMs inherit from the Super POM by default. The Super POM provides default configuration, such as default source directories, default plugins, and so on.

    68 . What Is Maven Archetype?

    Ans:

    • Archetype is a Maven project templating toolkit.
    • An archetype is defined as an original pattern or model from which all other things of the same kind are made.

    69 . What Is Maven Artifact?

    Ans:

    In Maven artifact is simply  a file or JAR that is deployed to a Maven repository. An artifact has

    • Group ID 
    • Artifact ID
    • Version string. The three together uniquely identify the artifact. All the  project dependencies are specified as artifacts.

    70 . What Is Goal In Maven?

    Ans:

    • In Maven a goal represents a specific task which contributes to the building and managing of a project.
    • It may be bound to 1 or many build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by its direct invocation.
    Gradle Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    71 . What Is Build Profile?

    Ans:

    • In Maven a build profile is a set of configurations. This set  is used to define or override default behaviour of Maven build.
    • Build profile helps the developers to customize the build process for different environments. For example you can set profiles for Test, UAT, Pre-prod and Prod environments each with its own configurations etc.

    72 . Explain what is POM?

    Ans:

    • In Maven, POM (Project Object Model) is the fundamental unit of work.
    • It is an XML file which holds the information about the project and configuration details used to build a project by Maven.

    73 . Explain what a Maven artifact?

    Ans:

    • Usually an artifact is a JAR file which gets arrayed to a Maven repository.
    • One or more artifacts a maven build produces such as compiled JAR and a source JAR.
    • Each artifact includes a group ID, an artifact ID and a version string.

    74 . Explain what is a Maven Repository? What are their types?

    Ans:

    • A Maven repository is a location where all the project jars, library jars, plugins or any other particular project related artifacts are stored and can be easily used by Maven.
    • Their types are local, central and remote

    75 . Why are Maven Plugins used?

    Ans:

    Maven plugins are used to

    • Create a jar file
    • Create war file
    • Compile code files
    • Unit testing of code
    • Documenting projects
    • Reporting

    76 . List out the dependency scope in Maven?

    Ans:

    The various dependency scope used in Maven are:

    • Compile: It is the default scope, and it indicates what dependency is available in the classpath of the project
    • Provided: It indicates that the dependency is provided by JDK or web server or container at runtime
    • Runtime: This tells that the dependency is not needed for compilation but is required during execution
    • Test: It says dependency is available only for the test compilation and execution phases
    • System: It indicates you have to provide the system path

    Import: This indicates that the identified or specified POM should be replaced with the dependencies in that POM’s section

    77 . Mention how profiles are specified in Maven?

    Ans:

    Profiles are specified in Maven by using a subset of the elements existing in the POM itself.

    78 . Explain how you can exclude dependency?

    Ans:

    By using the exclusion element, dependency can be excluded

    79 . Mention the difference between Apache Ant and Maven?

    Ans:

    • Apache Ant Maven
    • Ant is a toolbox – Maven is a framework.
    • Ant does not have formal conventions like project directory structure – Maven has conventions.
    • Ant is procedural; you have to tell to compile, copy and compress – Maven is declarative ( information on what to make & how to build).
    • Ant does not have lifecycle; you have to add sequence of tasks manually – Maven has a lifecycle.
    • Ant scripts are not reusable – Maven plugins are reusable.

    80 . In Maven what are the two setting files called and what are their location?

    Ans:

    • Maven, the setting files are called settings.xml, and the two setting files are located at

    Maven installation directory: $M2_Home/conf/settings.xml

    User’s home directory: ${ user.home }/ .m2 / settings.xml

    81 . List out what are the build phases in Maven?

    Ans:

    Build phases in Maven are

    • Validate
    • Compile
    • Test
    • Package
    • Install
    • Deploy

    82 . List out the build, source and test source directory for POM in Maven?

    Ans:

    Build = Target

    Source = src/main/java

    Test = src/main/test

    83 . Where do you find the class files when you compile a Maven project?

    Ans:

    You will find the class files ${basedir}/target/classes/.

    84 .  Explain what would the “jar: jar” goal do?

    Ans:

    jar: jar will not recompile sources; it will imply just create a JAR from the target/classes directory considering that everything else has been done

    85 . List out what are the Maven’s order of inheritance?

    Ans:

    The maven’s order of inheritance is

    • Parent Pom
    • Project Pom
    • Settings
    • CLI parameters

    86 . For POM what are the minimum required elements?

    Ans:

    The minimum required elements for POM are project root, modelVersion, groupID, artifactID and version.

    87 . Explain how you can produce execution debug output or error messages?

    Ans:

    To produce execution debug output you could call Maven with X parameter or e parameter.

    88 . Explain how to run test classes in Maven?

    Ans:

    To run test classes in Maven, you need surefire plugin, check and configure your settings in setting.xml and pom.xml for a property named “test.”

    89 . What is Spring Boot and mention the need for it?

    Ans:

    • Spring Boot is a Spring module which aims to simplify the use of the Spring framework for Java development.
    • It is used to a create stand-alone Spring-based applications which you can just run.
    • So, it basically removes a lot of configurations and dependencies.
    • Aiming at the Rapid Application Development, Spring Boot framework comes with the auto-dependency resolution, embedded HTTP servers, auto-configuration, management endpoints, and Spring Boot CLI.
    • So, if you ask me why should anybody use Spring Boot, then I would say, Spring Boot not only improves productivity but also provides a lot of conveniences to write your own business logic.

    90 . Mention the advantages of Spring Boot

    Ans:

    The advantages of Spring Boot are as follows:

    • Course Curriculum
    • Spring Framework Certification Training
    • Instructor-led SessionsReal-life Case StudiesAssignmentsLifetime Access
    • Provides auto-configuration to load a set of default configuration for a quick start of the application
    • Creates stand-alone applications with a range of non-functional features that are common to large classes of projects
    • It comes with embedded tomcat, servlet containers jetty to avoid the usage of WAR files
    • Spring Boot provides an opinionated view to reduce the developer effort and simplify maven configurations
    • Provides CLI tool to develop and test applications
    • Comes with Spring Boot starters to ensure dependency management and also provides various security metrics
    • Consists of a wide range of APIs for monitoring and managing applications in dev and prod.
    • Integrates with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security easily by avoiding boilerplate code.

    91 . Mention a few features of Spring Boot

    Ans:

    Few important features of Spring Boot are as follows:

    • Spring CLI – Spring Boot CLI allows you to Groovy for writing Spring boot application and avoids boilerplate code.
    • Starter Dependency – With the help of this feature, Spring Boot aggregates common dependencies together and eventually improves productivity
    • Spring Initializer – This is basically a web application, which can create an internal project structure for you. So, you do not have to manually set up the structure of the project, instead, you can use this feature.
    • Auto-Configuration – The auto-configuration feature of Spring Boot helps in loading the default configurations according to the project you are working on. In this way, you can avoid any unnecessary WAR files.
    • Spring Actuator –  This feature provides help while running Spring Boot applications.
    • Logging and Security – The logging and security feature of Spring Boot, ensures that all the applications made using Spring Boot are properly secured without any hassle.

    92 . Explain how to create Spring Boot application using Maven 

    Ans:

    Well, there are various approaches to create a Spring Boot application using maven, but if I have to name a few, then following are the ways to create a Spring Boot project/ application using maven:

    • Spring Boot CLI
    • Spring Starter Project Wizard
    • Spring Initializr
    • Spring Maven Project

    93 . Mention the possible sources of external configuration

    Ans:

    • There is no doubt in the fact that Spring Boot allows the developers to run the same application in different environments.
    • Well, this is done with the support it provides for external configuration.
    • It uses environment variables, properties files, command-line arguments, YAML files, and system properties to mention the required configuration properties.
    • Also, the value annotation is used to gain access to the properties. So, the most possible sources of external configuration are as follows:
    • Application Properties – By default, Spring Boot searches for the application properties file or its YAML file in the current directory, classpath root or config directory to load the properties.
    • Command-line properties – Spring Boot provides command-line arguments and converts these arguments to properties. Then it adds them to the set of environment properties.
    • Profile-specific properties –  These properties are loaded from the application-{profile}.properties file or its YAML file. This file resides in the same location as that of the non-specific property files and the{profile} placeholder refers to an active profile.

    94 . Can you explain what happens in the background when a Spring Boot Application is “Run as Java Application”?

    Ans:

    When a Spring Boot application is executed as “Run as Java application”, then it automatically launches up the tomcat server as soon as it sees, that you are developing a web application.

    95 . What are the Spring Boot starters and what are available the starters?

    Ans:

    • Spring Boot starters are a set of convenient dependency management providers which can be used in the application to enable dependencies.
    • These starters, make development easy and rapid. All the available starters come under the org.springframework.boot group. Few of the popular starters are as follows:

    Programming & Frameworks Training

    spring-boot-starter: – This is the core starter and includes logging, auto-configuration support, and YAML.

    spring-boot-starter-jdbc – This starter is used for HikariCP connection pool with JDBC.

    spring-boot-starter-web – Is the starter for building web applications, including RESTful, applications using Spring MVC.

    spring-boot-starter-data-jpa – Is the starter to use Spring Data JPA with Hibernate.

    spring-boot-starter-security – Is the starter used for Spring Security.

    spring-boot-starter-aop: This starter is used for aspect-oriented programming with AspectJ and  Spring AOP.

    spring-boot-starter-test: Is the starter for testing Spring Boot applications.

    96 . Explain Spring Actuator and its advantages

    Ans:

    • Spring Actuator is a cool feature of Spring Boot with the help of which you can see what is happening inside a running application.
    • So, whenever you want to debug your application, and need to analyze the logs you need to understand what is happening in the application right?
    • In such a scenario, the Spring Actuator provides easy access to features such as identifying beans, CPU usage, etc.
    • The Spring Actuator provides a very easy way to access the production-ready REST points and fetch all kinds of information from the web. These points are secured using Spring Security’s content negotiation strategy.

    97 . What is Spring Boot dependency management?

    Ans:

    Spring Boot dependency management is basically used to manage dependencies and configuration automatically without you specifying the version for any of that dependencies.

    98 . Can we change the port of the embedded Tomcat server in Spring boot?

    Ans:

    • Yes, we can change the port of the embedded tomcat server by using the application properties file.
    • In this file, you have to add a property of “server.port” and assign it to any port you wish to.
    • For example, if you want to assign it to 8081, then you have to mention server.port=8081.
    • Once you mention the port number, the application properties file will be automatically loaded by Spring Boot and the required configurations will be applied on to the application.

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free