Maven MCQs

Maven MCQs

These Maven multiple-choice questions and their answers will help you strengthen your grip on the subject of Maven. You can prepare for an upcoming exam or job interview with these 50 Maven MCQs.
So scroll down and start answering.

1: What element in the pom.xml file allows you to provide values that can be reused in other elements of the pom.xml?

A.   Plugins

B.   Build

C.   Properties

D.   Parent

2: If you wish to build and package your artifact using the Maven package goal but don't want to execute the unit tests, which environment variable and value would you use?

A.   Maven.test.ignore=TRUE


C.   Maven.test.skip=TRUE

D.   Maven.verify.execute=FALSE

3: When building a Maven EAR project and specifying the configuration of which projects to include, what is the element in the plugin configuration that contains Enterprise Java Bean projects?

A.   Modules/webModule

B.   Modules/ejbModule

C.   Modules/enterpriseModules

D.   Modules/services

4: The goal that is executed to generate and deploy a documentation website is _.

A.   Deliver

B.   Site

C.   Doc

D.   Deploy

5: What does the mvn -version command do?

A.   It builds your Maven project.

B.   It installs Maven on your computer.

C.   It updates Maven to the latest version.

D.   It print out your installed version of Maven.

6: There are several properties available for use in a pom.xml file that refer to details of the project, such as groupId and version. What do all of these properties start with?

A.   Pom

B.   Maven

C.   Jar

D.   Project

7: What directory structure contains the source code of your artifact?

A.   Src/code

B.   Src/test/java

C.   Src/main/java

D.   Src/main/resources

8: Which command is used to run the clean lifecyle followed by verify, install, and package with Maven?

A.   Mvn clean istall package

B.   Mvn package

C.   Mvn clean install

9: Which goal would you use with the Dependency plugin to determine which included dependencies are not used, as well as those you are using that you have not defined?

A.   Dependency:tree

B.   Dependency:properties

C.   Dependency:evaluate

D.   Dependency:analyze

10: In a multimodule project, if you have a plugin bound to a phase in the parent, it will be bound to the same phase in the module. What strategy could you employ to prevent the plugin from executing in the module?

A.   In the excluded element of the build section of the POM, list the plugin you do not want to run.

B.   Set the phase in the module to none.

C.   Set a value in the configuration of the plugin in the module to be excluded like this: TRUE.

D.   Do not specify the plugin in the module.

11: When building a web application with a WAR type project, which project directory should contain the style sheet, JavaScript, and other static file?

A.   Src/main/static

B.   Src/main/web

C.   Src/main/resources

D.   Src/main/webapp

12: When performing a build, which Maven plugin will allow you to set the specific version of the artifact to be built without manual modifying the pom.xml file?

A.   Compiler

B.   Surefire

C.   Versions

D.   Javadoc

13: When building a Maven Archetype, what is the filepath and file of the archetype descriptor that specifies how to lay out the prototype files?

A.   Src/main/template/descriptor.xml

B.   Src/main/resources/META-INF/maven/archetype-descriptor.xml

C.   Src/main/archetype/descriptor.xml

D.   Src/main/resources/META-INF/maven/maven-archetype.xml

14: What is a valid packaging type for a Maven project?

A.   WAR

B.   All of these answers

C.   POM

D.   EAR

15: When two dependencies of your Maven project introduce the same transitive dependency with different versions, which one(s) will be included in the dependency list for your project?

A.   The dependency with the higher version

B.   The transitive dependency that comes from the dependency listed first in the pom.xml file

C.   The transitive dependency that comes from the dependency listed last in the pom.xml file

D.   The transitive dependency version of the artifact that is closest to your project

16: Many organizations set up local mirrors to the Maven central repository. In order to leverage your company's Maven repository as a proxy for the Maven central repository, which element should you put into the settings.xml file?

A.   Replacements

B.   Proxies

C.   Mirrors

D.   LocalRepositories

17: Which Maven plugin would you leverage to specify the version of the compiler to target as well as the source level of the language?

A.   Versions

B.   Surefire

C.   Target

D.   Compiler

18: If your machine is behind a proxy, where should you specify the proxy server settings in order for Maven to access remote resources?

A.   .m2/proxy.txt

B.   Pom.xml

C.   Proxy.xml

D.   Settings.xml

19: What environment variable can you alter to increase the memory Maven uses?


B.   M2_HOME



20: How can you use Maven to run unit tests in parallel?

A.   It is not possible to do this.

B.   Implement the JUnit dependency and add a configuration that sets the parallel element to true.

C.   Specify the Maven Surefire Plugin and add a configuration that sets the parallel element to true.

D.   Move each test suite into a separate submodule.

21: What will the mvn dependency:tree command do?

A.   Verify the dependencies defined in the POM file.

B.   Print out a report of your project's dependencies in a tree format.

C.   Download all the transitive dependencies.

D.   Prune unused dependencies from your dependency tree.

22: How do you run a single unit test in Maven?

A.   Maven runs only a single unit test by default.

B.   Use the -Dtest= flag and pass in the name of the test.

C.   Use a plugin that can specify the test you want to run.

D.   It is not possible to do this.

23: How can Maven profiles be triggered?

A.   By explicitly calling the profiles using the -P flag

B.   Based on environment variables

C.   All of these answers

D.   Through Maven settings

24: Why will an mvn install command not deploy any artifacts to a remote repository?

A.   The name of the artifact must also be specified in the command.

B.   The name of the remote repository must also be specified in the command.

C.   Deploying artifacts to a remote repository must be done manually.

D.   The deploy phase of the default Maven lifecycle comes after the install phase.

25: Suppose you want to include a properties file in the JAR generated by your Maven build. What directory should you put it in?

A.   ${basedir}/src/main/resources

B.   ${basedir}/src/main/java/resources

C.   ${basedir}/resources

D.   ${basedir}/src/main/properties

26: Which structure in a settings.xml file allows for flexing properties based on some value for the runtime of Maven?

A.   Environment

B.   Properties

C.   Switch

D.   Profiles

27: What does it mean if the scope of a dependency is runtime?

A.   The dependency is not required to compile the project, but is needed at runtime.

B.   The dependency is needed at compile time and at runtime, and must be packaged for distribution.

C.   The dependency is needed at compile time and at runtime, but does NOT need to be packaged for distribution.

D.   The dependency is required for compilation.

28: If you want to utilitze a locally developed JAR file in another project and that JAR file has not been deployed to either the Maven central repository or your own locally sourced mirror repository, what Maven goal do you need to execute on the locally developed JAR project?

A.   Package

B.   Install

C.   Compile

D.   Test

29: What is the default packaging type for a Maven project build artifact?

A.   WAR

B.   JAR

C.   EAR

D.   POM

30: When defining a dependency that is included with the runtime container, what scope do you use in the pom.xml?

A.   Provided

B.   Compile

C.   Execution

D.   Runtime

31: What argument do you pass to Maven in order to update SNAPSHOT from the remote repository?

A.   -U

B.   -J

C.   -X

D.   -S

32: When performing a release using the Maven release plugin, which environment variable for batch mode is used to define the stamp placed in SCM to indicate the state of the artifact for the actual release?

A.   Tag

B.   ScmMark

C.   DevelopmentVersion

D.   ReleaseVersion

33: These are two general uses of plugins. The first is build and the second is _

A.   Reporting

B.   Servers

C.   Dependencies

D.   Distribution management

34: What does the mvn clean command do?

A.   It removes the target directory

B.   It updates the version of the plugins defined in the POM file.

C.   It removes unused dependencies in your project

D.   It builds your project

35: Suppose you are packaging a Maven project and see the following error: “[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!” What do you add to your POM file to set the platform encoding to ensure your build is not platform dependent?





36: Why might you not want to include groupId and version elements in child POM files?

A.   If you include these elements, an error will be thrown when you try to build the project.

B.   These elements are inherited from the parent POM file, and do not need to be repeated.

C.   Child POM files should include definitions of only dependencies and plugins.

D.   The values in the parent POM will be overridden by what is defined in the child POM.

37: The settings.xml file that provides the user-specific settings for Maven is contained in which directory by default?

A.   ${maven.home}/${}/settings.xml

B.   ${user.home}/.m2/settings.xml

C.   ${maven.home}/conf/settings.xml

D.   ${user.home}/maven/settings.xml

38: Suppose you are using Maven in a corporate environment and, to save bandwidth, you want to prevent the need for large numbers of developers to download the same dependency from the internet. What do you do to limit this?

A.   Create an internal corporate repository to store copies of the necessary artifacts.

B.   It is not possible to do this.

C.   When defining the dependency, set the scope to provided.

D.   Each developer should define the dependency in the POM file in the local copy of the project.

39: In multimodule projects, what do child POMs inherit from the parent POM?

A.   All of these answers

B.   Dependencies

C.   GroupId

D.   Version

40: Which build plugin allows you to create a "fat" JAR file that contains all of the dependencies in the final JAR file?

A.   Fatjar

B.   Shade

C.   Dependency

D.   Package

41: What is the default scope for Maven dependencies?

A.   Test

B.   Compile

C.   Runtime

D.   Build

42: What is one of the advantages of using properties in Maven?

A.   Properties provide a template for you to build Maven projects with a certain structure.

B.   Properties allow you to inherit values from the parent POM in the child POM.

C.   You can avoid hard-coding values in multiple places.

D.   Properties speed up your Maven build.

43: What are the phases of the clean lifecycle?

A.   Pre-clean,clean and post-clean

B.   Compile, clean and install

C.   Clean and install

D.   Validate, clean and deploy

44: For what purpose can plugins use the validate phase in the default lifecycle?

A.   To check the parent POM file defines all of the child POM files

B.   To carry out checks before building the project

C.   To ensure plugins defined in the POM file are in the correct order

D.   To check the project structure is correct after building a project

45: How do you check for unused dependencies in your project?

A.   Run mvn clean and look at which plugins are not mentioned in the output.

B.   You will need to do this manually.

C.   Include the Maven dependency plugin in your POM file and run the unpack goal.

D.   Run the analyze goal of the dependency plugin.

46: Why is it best practice to avoid overriding the default directory structure?

A.   Keeping the default structure reduces onboarding time, because developers recognize it.

B.   Overriding the default structure is very complex.

C.   Overriding the default structure will cause Maven to take longer to compile your code.

D.   All of these answers

47: What is the main purpose of the install phase?

A.   To compile the source code of the project

B.   To install all of the remote dependencies

C.   To deploy the final project artifacts into a remote Maven repository

D.   To copy the final project artifacts into the local Maven repository

48: How do you skip the tests when running a mvn package command?

A.   Use -Dtest=skip

B.   Use -DskipTests=true

C.   Use -Dtests=pass

D.   Use a plugin that can be configured to skip tests

49: What is the default value of the warSourceDirectory configuration property of the Maven WAR Plugin?

A.   /src/main/webapp

B.   /src/main/war

C.   /src/main/WEB-INF

D.   /src/web

50: When building a Maven Archetype, where do you put your prototype files?

A.   Src/main/template

B.   Src/main/archetype

C.   Src/main/resources/archetype-resources

D.   Src/main/java