Unit 4 - Practice Quiz
1 What is the primary purpose of a build tool like Maven in software development?
2 Which of the following problems is commonly solved by using automated builds?
3 Which file serves as the core configuration file for a Maven project, defining dependencies and plugins?
build.xml
maven.config
pom.xml
package.json
4 In Maven's standard directory layout, where is the main Java source code expected to be placed?
src/java/main
src/test/java
bin/java
src/main/java
5 What is a Maven build lifecycle?
6
Which Maven lifecycle phase translates the raw Java source code into bytecode (.class files)?
test
compile
validate
package
7
What is the primary function of the Maven package phase?
8 Which Maven phase copies the packaged artifact into the local repository, making it available as a dependency for other local projects?
deploy
verify
install
package
9 What is the main purpose of a Parent POM in Maven?
10 Which Maven dependency scope should be used for a library like JUnit, which is only needed when executing unit tests?
compile
test
runtime
provided
11 How does Maven handle dependencies of dependencies (i.e., when a library you need requires another library)?
12 Which POM section allows you to centralize the versioning of dependencies without actually including them in the project?
<dependencies>
<plugins>
<properties>
<dependencyManagement>
13
Which Maven plugin is responsible for running unit tests during the test phase?
14 What is the primary use of the Maven Shade plugin?
target directory
15
What is the main benefit of including the Maven Wrapper (mvnw) in a project's repository?
16
What does a plugin like dockerfile-maven-plugin allow developers to do?
17 When Dockerizing a Maven application, what is typically copied into the final Docker image?
pom.xml file without any source code
src folder and nothing else
18 In a continuous integration pipeline, where are final build artifacts (like JARs or Docker images) usually pushed for sharing and deployment?
19 How does Maven typically resolve version conflicts when the same transitive dependency is included multiple times with different versions?
20 Which Maven phase copies the final packaged artifact to a remote repository to share it with other developers and projects?
deploy
install
validate
test
21 A development team manually compiles their Java code, packages it, and copies it to a server. They frequently encounter the 'it works on my machine' syndrome. How does a build tool like Maven directly mitigate this specific issue?
22 When integrating an application into a CI/CD pipeline, which of the following is the primary problem solved by utilizing an automated build process rather than a manual one?
23
You need to define a custom version string 1.5.0 that will be used by multiple dependencies in your pom.xml. How should you define and reference this property?
<config><version>1.5.0</version></config> and reference it as $config.version.
<dependencyManagement><version>1.5.0</version></dependencyManagement> and reference it as ${version}.
<properties><app.version>1.5.0</app.version></properties> and reference it as ${app.version}.
<variables><app.version>1.5.0</app.version></variables> and reference it as @app.version@.
24
You are adding an application configuration file (app-config.xml) that must be present on the classpath during the execution of unit tests, but it MUST NOT be included in the final production JAR. Where should you place this file in the standard Maven directory structure?
25
A developer runs the command mvn install on a Maven project. Based on the default Maven lifecycle, which of the following phases will NOT be executed?
26 You want to ensure that your integration tests run and pass, and that the project meets quality criteria BEFORE it is copied into your local Maven repository. Which phase represents the culmination of these checks?
27
In a multi-module Maven project, you want to ensure that all child modules use version 2.5.4 of a library if they choose to declare it, but you do not want to force the library to be included in modules that don't need it. How do you configure this in the Parent POM?
<dependencies> section of the Parent POM.
<dependencyManagement> section of the Parent POM.
<plugins> section of the Parent POM.
<modules> section to hardcode the dependency into specific child modules.
28
You are developing a Java web application that uses the Servlet API. The application server (like Tomcat) will provide this API when the application is deployed. Which dependency scope should you use for javax.servlet-api to prevent it from being packaged in the final WAR file?
29 Your project depends on Library A, which internally depends on Library B (v1.0). However, your project also requires Library B directly, but you specifically need version 2.0. To avoid unpredictable classpath behavior, how should you handle this?
provided so its transitive dependencies are ignored.
src/main/resources folder.
<exclusion> tag inside Library A's dependency declaration to remove Library B, and explicitly declare Library B (v2.0) in your POM.
30
Your POM declares Dependency X first and Dependency Y second. Dependency X transitively brings in log-lib version 1.0. Dependency Y transitively brings in log-lib version 2.0. Both transitive dependencies are at the same depth in the dependency tree. According to Maven's mediation rules, which version of log-lib will be used?
31
What is the primary operational difference between declaring a dependency in <dependencies> versus <dependencyManagement>?
<dependencies> downloads artifacts from the local repository, while <dependencyManagement> forces a download from a remote repository.
<dependencies> is used for internal project modules, while <dependencyManagement> is used exclusively for external third-party libraries.
<dependencies> includes the library in the build and classpath, while <dependencyManagement> only specifies default configurations (like version) for dependencies declared elsewhere.
<dependencyManagement> is used for plugins, whereas <dependencies> is used for standard Java libraries.
32
Your local machine runs Java 11 by default, but you need the Maven Compiler Plugin to compile your code strictly for Java 17. How can you configure this in the pom.xml?
<java.version>17</java.version> in the <dependencies> section.
pom.xml packaging type to <packaging>java-17</packaging>.
maven-compiler-plugin to use <source>17</source> and <target>17</target> (or <release>17</release>).
-Djava=17 flag in the command line when running mvn compile.
33 During an emergency hotfix deployment, you need to build the project and compile the test classes, but you want to SKIP the actual execution of the unit tests to save time. Which command achieves this?
mvn install -Dmaven.test.skip=true
mvn install -P no-tests
mvn install -DskipTests
mvn install --exclude-tests
34 You are developing a standalone Java utility and want to package the application along with all of its dependencies into a single, executable 'uber-jar'. Which Maven plugin is best suited for this task and resolving potential classpath overlaps?
35
A new developer clones your project repository but does not have Maven installed on their system. The repository contains mvnw and mvnw.cmd files. What is the correct way for them to build the project?
mvnw only configures environment variables.
mvnw file into a local Maven installation.
./mvnw clean install which will automatically download the correct Maven version and execute the build.
mvn install --use-wrapper to trigger the build.
36
When using a Maven plugin to build Docker images (like dockerfile-maven-plugin or similar), how is the finalized JAR file name dynamically passed into the Dockerfile so that it can be copied into the image?
post-integration-test phase to rename the JAR to app.jar.
src/main/resources/application.properties.
<buildArgs> configuration in the plugin to map a Maven property like ${project.build.finalName} to an ARG in the Dockerfile.
37 You are writing a multi-stage Dockerfile to build a Maven application. To optimize the Docker build cache and avoid re-downloading dependencies every time the source code changes, what is the best sequence of instructions?
src/ folder, run mvn compile, then copy the pom.xml.
pom.xml, run mvn dependency:go-offline, then copy the source code and run mvn package.
mvn clean install locally on the host, then copy the target JAR into the Docker image.
pom.xml, then run mvn clean install.
38 When configuring Maven to deploy a built artifact to a remote private registry (like Nexus or Artifactory), you must provide authentication credentials. According to Maven security best practices, where should these credentials be stored?
src/main/resources/credentials.properties file.
pom.xml under the <repository> tag.
mvn deploy command.
~/.m2/settings.xml file mapped to the repository ID.
39
Your Java application connects to a MySQL database. You need the MySQL JDBC driver to connect at runtime, but your code is written exclusively using the generic java.sql interfaces, so the driver is not needed for compilation. Which dependency scope is most appropriate for the MySQL driver?
40
A CI/CD pipeline executes the command mvn clean deploy. How does Maven process this command?
clean phase simultaneously with the deploy phase using multithreading.
clean lifecycle, then runs only the deploy phase of the default lifecycle.
clean phase, then sequentially executes all default lifecycle phases starting from validate up to and including deploy.
compile and test to rapidly push the existing artifact to the remote repository.
41 In a Maven dependency tree, Project A depends on Lib B and Lib C. Lib B depends on Lib D (version 2.0). Lib C depends on Lib E, which in turn depends on Lib D (version 1.0). If Lib B is declared before Lib C in Project A's POM, which version of Lib D is included in the final artifact, and why?
<dependencyManagement> is explicitly used to resolve it.
42
Project A imports a Bill of Materials (BOM) in its <dependencyManagement> section, which specifies com.example:core-lib:1.0. In the <dependencies> section of Project A, com.example:core-lib is declared with version 2.0. Module B, a child of Project A, declares com.example:core-lib without a version. What version of core-lib does Module B resolve?
<dependencyManagement> takes absolute precedence over local declarations.
<dependencyManagement>, and this override is inherited.
43
A parent POM defines the maven-antrun-plugin exclusively inside the <pluginManagement> section and binds an execution to the validate phase. A child module inherits from this parent but does not mention the maven-antrun-plugin in its own POM. What happens when mvn validate is run on the child module?
maven-antrun-plugin executes during the validate phase of the child module.
<skip>false</skip> parameter to propagate to children.
<packaging>pom</packaging> configuration.
maven-antrun-plugin does not execute because <pluginManagement> only configures plugins; they must be explicitly declared in the child's <plugins> section to be invoked.
44
When creating an Uber JAR using the maven-shade-plugin for an application heavily utilizing the Spring Framework, the resulting JAR throws schema errors at runtime. This happens because multiple dependencies contain different META-INF/spring.handlers files. How must this be resolved in the Shade plugin configuration?
META-INF/spring.handlers from all dependencies using the <filters> configuration.
ServicesResourceTransformer to relocate the schema packages to a shaded directory.
ManifestResourceTransformer to specify a custom main class.
AppendingTransformer specifically mapped to the META-INF/spring.handlers resource.
45
A project declares Dependency X with <scope>provided</scope>. Dependency X transitively depends on Dependency Y with <scope>compile</scope>. What is the effective scope of Dependency Y in the root project?
46
When running integration tests with the maven-failsafe-plugin, what is the key functional difference between stopping at the integration-test phase versus proceeding to the verify phase?
maven-failsafe-plugin binds identically to both phases.
integration-test phase requires an active Docker daemon, while the verify phase is used purely for offline static analysis.
integration-test phase only compiles integration test sources; the actual execution occurs in the verify phase.
integration-test phase executes the tests but does not fail the build if tests fail; the verify phase evaluates the results and fails the build if necessary.
47
You are utilizing the Maven Wrapper (mvnw) to ensure uniform build environments. A developer's machine resides behind a strict corporate firewall that blocks direct access to Maven Central, preventing mvnw from downloading the Maven distribution. How can you configure the wrapper to fetch the Maven distribution from an internal Artifactory server?
distributionUrl property inside the .mvn/wrapper/maven-wrapper.properties file.
MAVEN_HOME environment variable on the developer's machine to point to the internal Artifactory.
settings.xml file in the .mvn directory to include a mirror for central.
<pluginRepositories> section of the project POM.
48
When utilizing the dockerfile-maven-plugin to build a Docker image, you want to dynamically pass the final built JAR filename into the Dockerfile as an argument. How is this correctly accomplished mapping Maven coordinates to Docker ARGs?
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE> inside the <environmentVariables> block of the plugin.
maven-assembly-plugin to app.jar and hardcoding COPY app.jar / in the Dockerfile.
maven-resources-plugin before the dockerfile-maven-plugin executes.
ARG JAR_FILE in the Dockerfile and passing <buildArgs><JAR_FILE>${project.build.finalName}.jar</JAR_FILE></buildArgs> in the plugin configuration.
49
A CI pipeline needs to push a compiled Maven artifact to a private Nexus repository. The repository URL is defined in the project's POM under <distributionManagement>. Authentication is required. Where and how must the credentials be configured to ensure Maven successfully authenticates during the deploy phase?
credentials.json file located in the .mvn directory.
<distributionManagement> block of the POM, using the <username> and <password> tags.
mvn deploy -Drepo.username=user -Drepo.password=pass.
~/.m2/settings.xml file under <servers>, mapping the <server><id> exactly to the <repository><id> specified in the POM's <distributionManagement>.
50
A developer executes mvn package -DskipTests. Which of the following accurately describes the behavior of the maven-surefire-plugin and the build lifecycle in this scenario?
@Ignore or @Disabled are skipped; all other unit tests are executed.
target/test-classes directory, but the actual execution of unit tests is bypassed.
test-compile and test phases.
51 To solve the problem of non-reproducible builds where two builds from identical source code generate JARs with different SHA-256 hashes, what Maven property should be configured to ensure deterministic archive entries?
<maven.build.timestamp.format>
<maven.compiler.deterministic>
<reproducible.builds.enabled>
<project.build.outputTimestamp>
52
A legacy Java project contains source code in both src/main/java and src/legacy/java. How can you correctly configure Maven to compile sources from both directories without breaking standard plugin lifecycles?
build-helper-maven-plugin with the add-source goal to register src/legacy/java as an additional source root.
src/legacy/java into src/main/resources and configure the <resources> tag.
<sourceDirectory>src/main/java,src/legacy/java</sourceDirectory> in the POM's <build> section.
maven-compiler-plugin <includes> tag to scan the root src directory recursively.
53
A project is defined with <packaging>pom</packaging>. You execute the command mvn deploy. Which of the following statements is true regarding the execution of the compiler and surefire plugins during this run?
mvn deploy cannot be executed on POM packaged projects.
deploy triggers all prior phases.
compiler plugin executes, but the surefire plugin is skipped automatically for POM projects.
54 When resolving the Effective POM, which of the following configuration sources has the highest overriding precedence for defining a specific property value?
pom.xml <properties> section.
~/.m2/settings.xml file.
<properties> section of the project's parent pom.xml.
55
When configuring the maven-compiler-plugin to run a custom annotation processor (e.g., MapStruct or Lombok), what is the effect of declaring the processor dependency inside the <annotationProcessorPaths> configuration tag rather than in the project's general <dependencies>?
<useSystemClassLoader>true) to bypass memory limits.
compile phase and only runs during the generate-sources phase.
56 When writing a multi-stage Dockerfile for a Maven application to optimize build caching, what is the correct order of operations to ensure that dependency downloading is cached as a separate Docker layer?
pom.xml RUN mvn compile COPY src RUN mvn package
src and pom.xml RUN mvn clean package
mvn clean install COPY target/app.jar ENTRYPOINT java -jar app.jar
pom.xml RUN mvn dependency:go-offline COPY src RUN mvn package
57
Project A declares direct dependencies on Module B and Module C. Module B depends on Lib D (v1.0). Module C also depends on Lib D (v1.0). If you explicitly declare an <exclusion> for Lib D inside the dependency block for Module B in Project A's POM, what happens to Lib D?
58
Which of the following restrictions applies to the import dependency scope in Maven?
<pluginManagement> section.
<type>pom</type> and must be placed inside the <dependencyManagement> section.
system scope but allows relative paths to local repositories.
<optional>true</optional> tag.
59
A custom Maven plugin has a goal specifically bound to the process-classes phase. A developer executes mvn test-compile. Will the custom plugin execute?
process-classes is part of the default lifecycle which occurs after test-compile.
process-classes precedes test-compile in the default build lifecycle.
test-compile creates an isolated lifecycle fork that excludes process phases.
test profile.
60
In a Maven tree, Dependency A requests Lib X with version range [1.0, 2.0). Dependency B requests Lib X with version range [1.5, 2.5]. If both A and B are included in a project, what version constraint will Maven use to resolve Lib X?
[1.5, 2.0).
2.5.
1.0.