- Published on
Interview Questions for Maven & Ant (Java)
- Authors
- Name
- Rahul Neelakantan
This post will answer the most common questions that the interviewer can ask regarding Ant and Maven. First, I will cover Maven, and next will go to Ant interview questions.
Table of Contents
- Maven Interview Questions
- List out the dependency scope in Maven?
- Mention how profiles are specified in Maven?
- Mention the difference between Apache Ant and Maven?
- List out the build phases in Maven?
- List out what are the Maven’s order of inheritance?
- For POM what are the minimum required elements?
- What are the advantages of Maven?
- What is the command to check the maven version?
- What is the fully qualified artifact name of maven project?
- What is an archetype?
- What does it mean when you say Maven uses Convention over Configuration?
- What phases does a Clean Life Cycle consist of?
- What phases does a Site Lifecycle consist of?
- What is the difference between Snapshot and Version?
- What is a transitive dependency in Maven?
- What is dependency exclusion?
- What is MOJO?
- What is meant by the term ‘Super POM’?
- What is Build Profile?
- How Maven handles and determines what version of dependency will be used when multiple versions of an artifact are encountered?
- What do you mean by Maven’s External Dependencies?
- Why is it recommended to keep the external dependencies in the local repository rather than a remote repository in Maven?
- Explain the error “You cannot have two plugin executions with the same ( or missing) elements” in Maven?
- Ant Interview Questions
- What Is Ant?
- Features of Ant?
- What Is Different Between Ant And Make?
- What Is Ivy?
- Explain How To Debug My Ant Script?
- Explain How To Use Runtime In Ant?
- Explain How To Modify Properties In Ant?
- In which language Ant is written?
- List some basic functions performed by Ant?
- What is Basedir in ant?
Maven Interview Questions
List out the dependency scope in Maven?
- 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
Mention how profiles are specified in Maven?
Profiles are specified in Maven by using a subset of the elements existing in the POM itself.
<project>
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>profile-2</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
</project>
Mention the difference between Apache Ant and Maven?
Ant | Maven |
---|---|
Ant is a toolbox | Maven is a framework. |
Ant does not have formal conventions like a 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 a lifecycle; you have to add a sequence of tasks manually. | Maven has a lifecycle. |
Ant scripts are not reusable. | Maven plugins are reusable. |
List out the build phases in Maven?
- Validate
- Compile
- Test
- Package
- Install
- Deploy
List out what are the Maven’s order of inheritance?
- Parent Pom
- Project Pom
- Settings
- CLI parameters
For POM what are the minimum required elements?
The minimum required elements for POM are project root, modelVersion, groupID, artifactID and version.
What are the advantages of Maven?
- No need to add jar file in each project
- Creates right directory structure
- Builds and deploys the project
What is the command to check the maven version?
mvn -version
What is the fully qualified artifact name of maven project?
<groupId>:<artifactId>:<version>
What is an archetype?
Archetype is the maven plugin. It creates the project structure.
What does it mean when you say Maven uses Convention over Configuration?
In Configuration, developers have to create the build processes manually, and they have to specify every configuration in detail. But, Maven uses convention where the developers need not create the build processes manually.
Also, for the convention, users do not need to specify the configuration in detail. Once a developer creates a project in Maven, then Maven will automatically create a structure. Developers have to place the files appropriately. There is no need to specify any configuration details in the pom.xml file.
What phases does a Clean Life Cycle consist of?
- pre-clean
- clean
- post-clean
What phases does a Site Lifecycle consist of?
- pre-site
- site
- post-site
- site-deploy
What is the difference between Snapshot and Version?
In the case of Version, if Maven once downloads the mentioned version, say codingjump:1.0, it will never try to download a newer 1.0 available in the repository. To download the updated code, the codingjump version is then upgraded to 1.1.
In the case of SNAPSHOT, Maven will automatically fetch the latest SNAPSHOT (codingjump:1.0-SNAPSHOT) every time the team builds its project.
What is a transitive dependency in Maven?
These are dependencies that are dependencies of your direct dependencies. Maven does need you to mention the transitive dependencies in POM.xml file
What is dependency exclusion?
When you build your project, that artifact will not be added to your project’s classpath by way of the dependency in which the exclusion was declared.
Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId, they are mostly for transitive dependencies.
Suppose if A depends upon B and B depends upon C. You can mark to exclude C if you’re not using B’s functionality that depends on C.
Dependency exclusion of transitive dependency is mostly done for below reasons:-
- It has a security risk
- It is not compatible with your Java version
- You’re not using it and don’t want to populate it in your project classpath
What is MOJO?
MOJO can be defined as a Maven plain Old Java Object. Every MOJO is an executable goal in Maven, and a plugin refers to the distribution of such MOJOs. MOJO enables Maven to extend the functionality that is already not found in it.
What is meant by the term ‘Super POM’?
Super POM refers to the default POM of Maven. The POMs of Maven can be derived from a parent or by default. To execute any particular objectives, effective POM is used.
Super POM supports the developers to configure the pom.xml file with the least configurations.
What is Build Profile?
A Build profile is a set of configuration values which can be used to set or override default values of Maven build. Using a build profile, you can customize builds for different environments such as Production v/s Development environments.
How Maven handles and determines what version of dependency will be used when multiple versions of an artifact are encountered?
If two dependency versions are at the same depth in the dependency tree, the first declared dependency will be used. This is called dependency mediation.
What do you mean by Maven’s External Dependencies?
Once Maven reads through the pom file, it gets to know the list of dependencies for the project. It searches for these dependencies in Local, Central and Remote repositories. In case any of the dependencies are not found in any of the repositories, then Maven utilizes the external dependency.
Why is it recommended to keep the external dependencies in the local repository rather than a remote repository in Maven?
It is recommended to keep the external dependencies in the local repository instead of remote in Maven because the local repository consumes less space, is easily accessible and there is no need to take care of versioning for jars.
Explain the error “You cannot have two plugin executions with the same ( or missing) elements” in Maven?
This error message comes when we have run a single plugin more than one time with the same id. We need to give a unique id for each execution.
Ant Interview Questions
What Is Ant?
Ant is an open source code .It is Java-based build tool sponsored by Apache Software Foundation. It is a program for putting all the pieces of a program together. A simple definition might state that “Ant is a Java-based build tool from Apache Software Foundation”.
Features of Ant?
Open: Ant is an open-source project available under the Apache license. Therefore, its source code can be downloaded and modified.
Additionally, Ant uses XML build files which make its development easy.
Cross Platform: Use of XML along with Java makes Ant makes it the perfect solution for developing programs designed to run or be built across a range of different operating systems.
Extensible: New tasks are used to extend the capabilities of the build process, while build listeners are used to help hook into the build process to add extra error tracking functionality.
Integration: As Ant is extensible and open, it can be integrated with any editor or development environment easily.
What Is Different Between Ant And Make?
The most important difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make uses its Makefile format. By default the ant XML file is named build.xml.
What Is Ivy?
Ivy is a popular dependency manager .IVY is basically focused on flexibility and simplicity.
Explain How To Debug My Ant Script?
- By using project.log (“message”) in the java script or the customized ant task.
- By running Ant with
–verbose / -debug
options. These options provide more information on what is happening
Explain How To Use Runtime In Ant?
There is no need to use Runtime in ant. Because ant has a Runtime counterpart by the name ExecTask. ExecTask is in the package org.apache.tools.ant.taskdefs. The Task is created by using the code in the customized ant Task. The code snippet is as follows:
ExecTask execTask = (ExecTask)project.createTask("exec");
Explain How To Modify Properties In Ant?
We can not modify the properties in ant. The properties in ant are immutable in nature.
In which language Ant is written?
Ant is written in Java.
List some basic functions performed by Ant?
- Compiling Java code into bytecode
- Placing this bytecode in a package
- Deployment to production systems
- Document creation and release notes preparation.
What is Basedir in ant?
The ‘basedir’ is the base directory from which any relative directories used within the Ant build file are referenced from. If this is omitted the parent directory of the build file will be used.