DevOps / Maven Interview questions II
1. Explain Build Profile in Maven.
A Build profile represents a set of configuration that is used to set or override default values of a Maven build. Using a build profile, a maven build can be customized for various application environments such as Production, Testing, Staging...
2. What are different types of Build Profiles in Maven?
There are 4 different types of build profile. Per Project.
3. What are the build lifecycles of Maven?
There are 3 built-in build lifecycles. The default lifecycle handles your project deployment....
4. Explain package phase in Maven build lifecycle.
package phase pulls the compiled code and package it to a distributable format, such as a JAR. The below is the command to package a maven project.
5. What are the phases of 'site' lifecycle in Maven?
The following are the phases of site lifecycle in Maven. pre-site, site, post-site, and site-deploy.
6. What is local repository in Maven?
Maven local repository is located in your local system and is created by the maven when you run any maven command. By default, maven local repository is %USER_HOME%/.m2 directory....
7. What is Maven Central Repository?
Maven central repository is located on the web created by the apache maven community. The path of central repository is: http://repo1.maven.org/maven2/.
8. Explain Maven remote repository.
Remote repositories refer to any other type of repository, accessed by a variety of protocols such as file:// and http://. These repositories are set up by a third party to provide their artifacts for downloading....
9. How do I include dependencies in a jar using Maven?
Using jar-with-dependencies as the descriptorRef of your assembly-plugin configuration, we can create a JAR along its dependencies. This built-in descriptor creates an assembly with the classifier jar-with-dependencies using the JAR archive format....
10. Difference between Apache Ant and Maven.
Ant and Maven are build tools provided by Apache Foundation. The purpose of these tools is to simplify the build process of a project....
11. Create an executable JAR with dependencies using Maven.
To build an executable jar using maven, we need to add manifest configuration to the maven-assembly-plugin. The below subset of pom.xml configure maven-assembly-plugin to create a single executable jar.
12. Configuring resource directories in Maven.
By default, Maven configures and lookup into the src/main/resources directory for your project resources. Also additional resources directories could be specified by adding the configuration to the project's Pom.xml.
13. How do I enable connection to the central repository through the firewall in my organization?
The HTTP proxy settings need to be specified in the file settings.xml. The encrypted passord could be specified in the file....
14. Difference between repository and dependency in Maven.
Repository is a collection of artifacts (eg: jars). You can think of it as a mere storage / cache of various artifacts....
15. What does the POM comprise of in Maven?
Maven POM contains the some of the following configuration. project version.
16. What is an Archetype in Maven framework?
Archetype is a Maven plugin that creates a project structure as per its template. The below is the command to create a new maven project based on an archetype.
17. What are the uses of Maven Plugins?
Maven plugin helps in, Creating jar and war. Compiling source code.
18. What are the types of Maven Plugins?
There are 2 types of maven plugins. Build plugins execute during the build and should be configured in the element of pom.xml....
19. maven-surefire-plugin.
The Surefire Plugin is applied during the test phase of the build lifecycle to execute the unit tests of an application. It also generates reports.
20. maven-surefire-plugin report directory.
By default, the reports are generated at ${basedir}/target/surefire-reports.
21. List the report file formats.
Plain text file (*.txt) XML file (*.xml)
22. What is goal in Maven?
A maven goal represents a specific task that contributes to the building and managing of a Maven project. It may be bound to zero or more build phases....
23. Goals of Surefire Plugin.
surefire:test, the only goal of the surefire plugin, runs the unit tests of an application.
24. How do you invoke the surefire Plugin?
By calling, mvn test
25. Difference between Snapshot and Version in Maven.
In terms of version, when maven has downloaded a dependency project version 1.0, it will not download again the latest version of 1.0 while building the project. To facilitate the latest version the dependent project need to do upgrades it's...
26. What are the phases of 'clean' lifecycle in Maven?
The clean lifecycle consists of the following phases. pre-clean, clean, and post-clean.
27. Difference between install and deploy command in Maven.
mvn:install copies your packaged Maven module to your local repository (by default, in ~/.m2/repository), to be accessed by other local Maven builds. mvn:deploy uploads your packaged Maven module to another (usually remote) repository, to be accessed by others.
28. Difference between package and install in Maven.
package : takes the compiled code and package it to its distributable format, such as a JAR. install : installs the package into the local repository, for use as a dependency in other projects locally.
29. Difference between POM and Effective POM in Maven.
All Maven POMs inherit defaults from the Super POM. For a basic Java project, we just need the Simplest POM, that defines a groupId, artifactId, and version, the three required coordinates for every project....
30. How do I exclude all the transitive dependencies of a single dependency in Maven?
In Maven2, exclude a every single transitive dependency using separate <exclusion> list which is complex. In Maven3 the use of wildcard is allowed on both groupId and artifactId that exclude all dependencies that propagates through to the module using this...
31. Maven: How do I rename the war file for the project?
use the finalName tag to define/change the name of the war file in the web module that produces the war. See the below example.
32. List out the aspects does Maven Manages?
Maven handles following aspects, Build. Documentation.
33. Maven: how do you display execution debug output or error messages?
To view/display execution debug output call Maven with X parameter or e parameter.
34. Difference between Maven and Jenkins/Teamcity/Hudson.
Maven is a build tool and also provides dependency management, standard project layout and project management. Jenkins/Teamcity/Hudson is a continuous integration tool which is much more than build tool....
35. How do I prevent the propagation of plugins to child POMs?
Setting inherited tag to false prevents the propagation to child POMs.
36. How to find the POM that contains missing transitive dependency?
Run "mvn -X" command.
37. What does the Maven command mvn clean do?
This command erase the target directory with all the build data before starting the building process.
38. How a new archetype based project be created from command line?
A new project can be created using the command mvn archetype:generate .
39. How do I compile the application sources using Maven from command line.
Run the mvn compile command from the folder location where Pom.xml exists.
40. Can a Maven project have multiple parents?
Maven does not support multiple inheritance and a project can have only one parent. The parent project can have its own hierarchy.
41. Explain 'pom' packaging in Maven.
Pom packaging is used aggregate other projects and it acts as a container for sub modules within that project. Pom packaging is also used to identify the parent in non-modular context.
42. What is Maven relocation?
Maven relocation identifies the projects/artifacts that are relocated or moved on the repository. <project> <modelVersion> 4.0.0 </modelVersion> <groupId> bar </groupId> <artifactId> foo </artifactId> <version> 1.0 </version> <distributionManagement> <relocation> <groupId> org.bar </groupId> </re
43. Can we change the .m2 folder to any other name like .p2 or something? How?
Yes . The local repo folder name can be changed by updating in the settings.xml ....
44. Difference between mvn install and package.
mvn package takes the compiled code and package it in its distributable format, such as a JAR. mvn install installs the package into the local repository, for use as a dependency in other projects locally.
45. What is JAXB2 maven plugin and where will you use it?
JAXB2 maven plugin wraps and enhances the JAXB Schema Compiler (XJC) and allows compiling XML Schemas (as well as WSDL, DTDs, RELAX NG) into Java classes in Maven builds. This is plugin is used to generate web service clients from...
46. What is Maven BOM?
BOM (Bill Of Materials) is a special kind of POM used to control the versions of a project's dependencies and provide a central place to define and update those versions. BOM provides the flexibility to add a dependency to our...
47. What is the difference between -DskipTests and -Dmaven.test.skip=true?
-DskipTests compiles the tests, but skips running them. -Dmaven.test.skip=true skips compiling the tests and does not run them.