Maven Interview Questions-2
What is the difference between Maven and Ant?
Maven is a more advanced and modern build tool than Ant. Maven uses conventions over configuration, has a centralized repository, and supports plugins and dependencies management. Ant, on the other hand, is more flexible and requires manual configuration.
What is a POM file in Maven?
A POM (Project Object Model) file is an XML file that contains the project's configuration and dependencies. It is located in the root of the project and is used by Maven to build and manage the project.
What are the build lifecycle phases in Maven?
The default build lifecycle phases in Maven are: validate, compile, test, package, install, and deploy. Each phase corresponds to a specific goal and can be executed by invoking the corresponding command.
What is a Maven repository?
A Maven repository is a directory or a web server that stores the project's dependencies and plugins. Maven uses the repositories to resolve the dependencies and plugins required for the build process.
What is a Maven plugin?
A Maven plugin is a collection of goals that can be invoked from the command line or from the POM file. Plugins are used to perform tasks such as compiling, testing, and packaging the project.
What is a Maven dependency?
A Maven dependency is a library or a module that a project needs in order to build and run. Dependencies are defined in the POM file and are automatically downloaded and added to the classpath by Maven.
How do you manage dependencies in Maven?
Dependencies in Maven are managed by specifying the groupId, artifactId, and version of the dependency in the POM file. Maven will automatically download and add the dependency to the classpath.
How do you add a plugin to a Maven project?
Plugins can be added to a Maven project by specifying the groupId, artifactId, and version of the plugin in the POM file's build section.
What is the difference between a compile and a provided scope in Maven?
The compile scope indicates that the dependency is required for both compilation and execution, while the provided scope indicates that the dependency is required for compilation but will be provided at runtime by the container.
How do you create a custom Maven plugin?
A custom Maven plugin can be created by extending the org.apache.maven.plugin.AbstractMojo class and implementing the execute() method. The plugin should also be packaged and deployed to a Maven repository.
How do you deploy a Maven project to a remote repository?
A Maven project can be deployed to a remote repository by using the mvn deploy command or by configuring the distributionManagement section in the POM file. The remote repository should be specified in the POM file and the appropriate credentials should be provided.
How do you create a multi-module Maven project?
A multi-module Maven project can be created by defining multiple modules in the parent POM file and specifying the path to the child modules. Each child module should have its own POM file and can be built and deployed independently.
How do you run a specific goal in Maven?
A specific goal can be run in Maven by using the mvn goal:goalName command. For example, mvn compile will run the compile goal.
How do you skip test in Maven?
Tests can be skipped in Maven by using the -Dmaven.test.skip=true command line option or by specifying the skipTests property in the POM file.
How do you configure a Maven proxy?
A Maven proxy can be configured by specifying the proxy settings in the settings.xml file or by using the -Dhttp.proxyHost=hostname -Dhttp.proxyPort=port command line options.
How do you configure a Maven profile?
A Maven profile can be configured by specifying the profile in the POM file or settings.xml file. Profiles can be activated by using the -P command line option or by specifying the activeProfile property.
Leave a Comment