What is Maven?
Maven is a project management and comprehension tool. Maven provides developers a complete build lifecycle framework. Development team can automate the project’s build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.
What are the aspects Maven manages?
Maven provides developers ways to manage following −
- Builds
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
- mailing list
What is POM?
POM stands for Project Object Model. It is fundamental Unit of Work in Maven. It is an XML file. It always resides in the base directory of the project as pom.xml. It contains information about the project and various configuration details used by Maven to build the project(s).
What information does POM contain?
POM contains the some of the following configuration information −
- project dependencies
- plugins
- goals
- build profiles
- project version
- developers
- mailing list
What is Maven artifact?
An artifact is a file, usually a JAR that gets deployed to a Maven repository. A Maven build produces one or more artifacts, such as a compiled JAR and a “sources” JAR.
Each artifact has a group ID (usually a reversed domain name, like com.example.foo), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact. A project’s dependencies are specified as artifacts.
Name the 3 build lifecycle of Maven.
The three build lifecycles are −
clean:cleans up artifacts created by prior builds.
default (or build):This is used to build the application.
site: generates site documentation for the project.
What are the phases of a Maven Build Lifecycle?
Following are the phases −
validate − validate the project is correct and all necessary information is available.
compile − compile the source code of the project.
test − test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package − take the compiled code and package it in its distributable format, such as a JAR.
integration-test − process and deploy the package if necessary into an environment where integration tests can be run.
verify − run any checks to verify the package is valid and meets quality criteria.
install − install the package into the local repository, for use as a dependency in other projects locally.
deploy − done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
List the differences between ANT and Maven?
Ant | Maven |
Ant doesn’t have formal conventions, so we need to provide information about the project structure in the build.xml file. | Maven has a convention to place source code, compiled code, etc. So we don’t need to provide information about the project structure in pom.xml file. |
Ant is procedural, you need toprovide information about what to do and when to do through code. You need to provide order. | Maven is declarative, everything you define in the pom.xml file. |
There is no life cycle in Ant. |
There is a life cycle in Maven. |
Ant is a toolbox. | Maven is a framework. |
It is mainly a build tool. | It’s mainly a project management tool. |
The ant scripts are not reusable. | The maven plugins are reusable. |
It is less preferred than Maven. | It is more preferred than Ant. |
What are the main features of Maven?
Some of the main features of Maven are:
- Simple to use: Maven provides easy project settings that are based on genuine practices.
- Fast: You can receive a fresh project or module that began in fewer seconds in Maven.
- Easy to learn: Maven usage and commands are pretty easy to learn across all projects.Therefore ramp-up time for new developers coming onto a project is very less.
- Dependency management: Maven provides superior dependency management including automatic updates and transitive dependencies.
- Multiple Projects: You can easily work on multiple projects at the same time by using Maven.
- Huge Library: Maven has a large and growing repository of libraries and metadata to use out of the box.
What does the build tool?
- Generates source code (if the auto-generated code is used)
- Generates documentation from source code
- Compiles source code
- Packages compiled code into a JAR or ZIP file
- Installs the packaged code in the local repository, server repository, or central repository
Mention the steps for installing Maven on windows.
Maven can be downloaded and installed on windows, linux, and MAC OS platforms. To install Maven on windows, you need to perform the following steps:
- Download Maven and extract it.
- Add JAVA_HOME and MAVEN_HOME in the list of environment variables.
- Add the environment path in Maven variable.
- The last step is the verification of Maven by checking its version.
What are the aspects Maven manages?
Maven provides developers ways to manage following −
- Builds
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
- mailing list
What is Maven artifact?
- An artifact is a file, normally a JAR that gets deployed to a Maven repository. A Maven build creates one or more artifacts, such as a compiled JAR and a source JAR.
- Each artifact consists of a group ID, an artifact ID, and a version string. The three together uniquely identify the artifact. A project’s dependencies are specified as artifacts.
What phases does a Clean Lifecycle consist of?
The clean lifecycle consists of the following phases −
- pre-clean
- clean
- post-clean
What phases does a Site Lifecycle consist of?
- The phases in Site Lifecycle are −
- pre-site
- site
- post-site
- site-deploy
How can you activate profiles?
A Maven Build Profile can be activated in the following ways −
- Explicitly using command console input.
- Through maven settings.
- Based on environment variables (User/System variables).
- OS Settings (for example, Windows family).
- Present/missing files.
What types of Maven repository?
Maven repositories are of three types –
Local: Maven local repository is a folder location that is present on your machine. It is created when you run any maven command for the first time. Maven local repository is a location where you can find your project’s all dependencies (library jars, plugin jars etc).
Central: It is a repository provided by the Maven community. It contains a huge collection of commonly used libraries. When Maven does not find any dependency in local repository, it starts searching in central repository using the following URL: http://repo1.maven.org/maven2/.
Remote: Sometimes, Maven is not able to find a mentioned dependency in the central repository as well then it stops the build process and an output error message is displayed on the console. To avoid such a situation, Maven provides the idea of Remote Repository which is nothing but the developer’s own custom repository containing required libraries or other project jars.
What are the uses of Maven Plugins?
Maven Plugins are used to −
- create jar file.
- create war file.
- compile code files.
- unit testing of code.
- create project documentation.
- create project reports.
What are the types of Maven Plugins?
Maven provides the following two types of Plugins −
Build plugins −They come into picture during the build and should be configured in the <build/> element of pom.xml
Reporting plugins −They get executed during the site generation and they should be configured in the <reporting/> element of the pom.xml
What are the things that you must define for each external dependency?
External dependencies (library jar location) can be configured in pom.xml in same way as other dependencies are configured.
- First, specify groupId the same as the name of the library.
- Then specify artifactId the same as the name of the library.
- Thirdly, specify scope as a system.
- Lastly, specify the system path relative to the project location.
What is Archetype?
An archetype is a Maven plugin whose task is to create a project structure as per its template.
What is the command to create a new project based on an archetype?
Type the following command − mvn archetype:generate
What is SNAPSHOT in Maven?
SNAPSHOT can be defined as a special version that indicates a current development copy. Unlike the regular versions, Maven checks for a new SNAPSHOT version in its remote repository. Maven does it for every build.
What is the dependency scope? Name all the dependency scope.
Dependency scope typically includes dependencies as per the current stage of the build. The various Dependency scopes are −
compile − This scope indicates that dependency is available in the classpath of the project. It is the default scope.
provided − This indicates that the dependency is to be provided by JDK or web-Server/Container at runtime.
runtime − This scope tells that you dont need dependency is for compilation but you need it for for execution.
test − This scope states that the dependency is only available for the test compilation and execution phases.
system − This scope indicates that you must provide the system path.
import − This scope is only used when the dependency is of type pom. This scope tells that the specified POM should be replaced with the dependencies in the POM’s <dependencyManagement> section.
What is a project’s fully qualified artifact name?
<groupId>:<artifactId>:<version>
If you fail to define any information, where does your pom inherits that information from?
All POMs are inherited from a parent despite explicitly defined or not. This base POM is called Super POM and it contains values that are inherited by default.
How profiles are specified in Maven?
Profiles are specified by making use of a subset of the elements that are available in the POM itself.