Unit 4: Maven Build Automation - Practice Quiz

INT332 — Devops Virtualization And Configuration Management 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary purpose of a build tool like Maven in software development?

Why build tools exist Easy
A. To design the user interface of web applications
B. To manage relational databases
C. To write code for the developers automatically
D. To automate processes like compiling, testing, and packaging code

2 Which of the following problems is commonly solved by using automated builds?

Problems solved by automated builds Easy
A. Network hardware failures
B. Designing application architecture
C. Writing unit test logic
D. Inconsistent and error-prone manual compilation steps

3 Which file serves as the core configuration file for a Maven project, defining dependencies and plugins?

Project Object Model (POM) Easy
A. pom.xml
B. maven.config
C. package.json
D. build.xml

4 In Maven's standard directory layout, where is the main Java source code expected to be placed?

Directory structure Easy
A. bin/java
B. src/main/java
C. src/java/main
D. src/test/java

5 What is a Maven build lifecycle?

Build lifecycle phases Easy
A. A well-defined sequence of phases to build and distribute a project
B. A tool for monitoring server performance
C. A graphical user interface for writing code
D. A database schema migration tool

6 Which Maven lifecycle phase translates the raw Java source code into bytecode (.class files)?

compile Easy
A. test
B. compile
C. package
D. validate

7 What is the primary function of the Maven package phase?

package Easy
A. To bundle the compiled code into a distributable format like a JAR or WAR
B. To compile the test source code
C. To download dependencies from the internet
D. To deploy the application to a live server

8 Which Maven phase copies the packaged artifact into the local repository, making it available as a dependency for other local projects?

install Easy
A. install
B. verify
C. deploy
D. package

9 What is the main purpose of a Parent POM in Maven?

Parent POM Easy
A. To act as the main executable file of the application
B. To convert Java code into Python code
C. To securely store passwords and API keys
D. To share common configurations and dependency versions across multiple sub-projects

10 Which Maven dependency scope should be used for a library like JUnit, which is only needed when executing unit tests?

Dependency scope Easy
A. test
B. compile
C. runtime
D. provided

11 How does Maven handle dependencies of dependencies (i.e., when a library you need requires another library)?

Transitive dependencies Easy
A. It ignores them, causing runtime errors
B. It requires you to write a custom bash script to fetch them
C. It prompts the user to download them manually
D. It automatically pulls them in as transitive dependencies

12 Which POM section allows you to centralize the versioning of dependencies without actually including them in the project?

Using dependency Management Easy
A. <properties>
B. <dependencyManagement>
C. <plugins>
D. <dependencies>

13 Which Maven plugin is responsible for running unit tests during the test phase?

Surefire plugin (unit testing) Easy
A. Maven Surefire Plugin
B. Maven Deploy Plugin
C. Maven Shade Plugin
D. Maven Compiler Plugin

14 What is the primary use of the Maven Shade plugin?

Shade plugin (uber jar) Easy
A. To delete the target directory
B. To automatically format Java code
C. To encrypt the source code
D. To create an "uber-jar" (fat jar) that contains both the compiled project code and all its dependencies

15 What is the main benefit of including the Maven Wrapper (mvnw) in a project's repository?

Maven wrapper (mvnw) Easy
A. It automatically writes unit tests for the project
B. It creates Docker containers automatically
C. It speeds up the compilation process by 50%
D. It allows developers to build the project without having to install Maven manually on their system

16 What does a plugin like dockerfile-maven-plugin allow developers to do?

Maven and Docker Integration: dockerfile-maven-plugin Easy
A. Run Docker inside a Java Virtual Machine
B. Compile Java code into Docker-compatible C++ code
C. Build and push Docker images directly as part of the Maven build process
D. Replace Maven entirely with Docker Compose

17 When Dockerizing a Maven application, what is typically copied into the final Docker image?

Dockerizing Maven-based applications Easy
A. The packaged artifact (e.g., JAR or WAR file) generated by Maven
B. The pom.xml file without any source code
C. The developer's IDE settings
D. The entire 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?

Pushing artifacts to registries Easy
A. A local Git branch
B. A relational database management system
C. A text document on a shared drive
D. An artifact repository or container registry (e.g., Nexus, Artifactory, Docker Hub)

19 How does Maven typically resolve version conflicts when the same transitive dependency is included multiple times with different versions?

Version conflicts & resolution Easy
A. It merges the source code of both versions
B. It randomly selects a version
C. It uses the "nearest definition" strategy in the dependency tree
D. It always chooses the oldest version

20 Which Maven phase copies the final packaged artifact to a remote repository to share it with other developers and projects?

deploy Easy
A. install
B. test
C. deploy
D. validate

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?

Why build tools exist Medium
A. By standardizing the build process, dependency resolution, and environment expectations into a single configuration file.
B. By installing a localized IDE on every developer's machine to enforce syntax checking.
C. By automatically writing unit tests for the source code to ensure cross-platform compatibility.
D. By dynamically converting Java source code into platform-native executable binaries.

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?

Problems solved by automated builds Medium
A. Bypassing the compilation phase to directly package source code into deployable containers.
B. Automatically fixing compilation errors and syntax warnings in the developer's source code.
C. Ensuring reproducible, error-free builds that do not rely on human intervention or specific developer environments.
D. Eliminating the need for source code version control repositories like Git.

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?

Project Object Model (POM) Medium
A. Define it inside <config><version>1.5.0</version></config> and reference it as $config.version.
B. Define it inside <variables><app.version>1.5.0</app.version></variables> and reference it as @app.version@.
C. Define it inside <properties><app.version>1.5.0</app.version></properties> and reference it as ${app.version}.
D. Define it inside <dependencyManagement><version>1.5.0</version></dependencyManagement> and reference it as ${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?

Directory structure Medium
A. src/test/java
B. src/test/resources
C. target/test-classes
D. src/main/resources

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?

Build lifecycle phases Medium
A. test
B. deploy
C. compile
D. package

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?

validate, compile, test, package, verify, install, deploy Medium
A. install
B. test
C. package
D. verify

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?

Parent POM Medium
A. Use the <modules> section to hardcode the dependency into specific child modules.
B. Define the library within the <dependencyManagement> section of the Parent POM.
C. Define the library within the <dependencies> section of the Parent POM.
D. Define the library within the <plugins> section of the Parent POM.

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?

Dependency scope Medium
A. test
B. runtime
C. provided
D. compile

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?

Transitive dependencies Medium
A. Declare Library B (v2.0) in the src/main/resources folder.
B. Maven automatically resolves all version conflicts by always downloading the oldest version of a transitive dependency.
C. Use the <exclusion> tag inside Library A's dependency declaration to remove Library B, and explicitly declare Library B (v2.0) in your POM.
D. Change Library A's scope to provided so its transitive dependencies are ignored.

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?

Version conflicts & resolution Medium
A. Version 2.0, because Maven always resolves to the highest version number available.
B. Version 2.0, because the last declared dependency overrides earlier ones.
C. The build will fail immediately due to a version conflict.
D. Version 1.0, because Maven uses the 'first declaration wins' strategy when depths are equal.

31 What is the primary operational difference between declaring a dependency in <dependencies> versus <dependencyManagement>?

Using dependency Management Medium
A. <dependencyManagement> is used for plugins, whereas <dependencies> is used for standard Java libraries.
B. <dependencies> downloads artifacts from the local repository, while <dependencyManagement> forces a download from a remote repository.
C. <dependencies> is used for internal project modules, while <dependencyManagement> is used exclusively for external third-party libraries.
D. <dependencies> includes the library in the build and classpath, while <dependencyManagement> only specifies default configurations (like version) for dependencies declared elsewhere.

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?

Maven Plugins & Execution: Compiler plugin Medium
A. Set <java.version>17</java.version> in the <dependencies> section.
B. Pass the -Djava=17 flag in the command line when running mvn compile.
C. Change the pom.xml packaging type to <packaging>java-17</packaging>.
D. Configure the maven-compiler-plugin to use <source>17</source> and <target>17</target> (or <release>17</release>).

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?

Surefire plugin (unit testing) Medium
A. mvn install -Dmaven.test.skip=true
B. mvn install -P no-tests
C. mvn install --exclude-tests
D. mvn install -DskipTests

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?

Shade plugin (uber jar) Medium
A. maven-shade-plugin
B. maven-compiler-plugin
C. maven-surefire-plugin
D. maven-dependency-plugin

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?

Maven wrapper (mvnw) Medium
A. They should run mvn install --use-wrapper to trigger the build.
B. They can run ./mvnw clean install which will automatically download the correct Maven version and execute the build.
C. They must manually download and install Maven first, as mvnw only configures environment variables.
D. They must run a Docker container to parse the mvnw file into a local Maven installation.

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?

Maven and Docker Integration: dockerfile-maven-plugin Medium
A. By using the <buildArgs> configuration in the plugin to map a Maven property like ${project.build.finalName} to an ARG in the Dockerfile.
B. By hardcoding the JAR name inside the Dockerfile, as Maven plugins cannot pass dynamic variables to Docker.
C. By setting the Docker container's environment variable inside the src/main/resources/application.properties.
D. By writing a Bash script in the post-integration-test phase to rename the JAR to app.jar.

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?

Dockerizing Maven-based applications Medium
A. Copy only pom.xml, run mvn dependency:go-offline, then copy the source code and run mvn package.
B. Run mvn clean install locally on the host, then copy the target JAR into the Docker image.
C. Copy all source code and pom.xml, then run mvn clean install.
D. Copy only the src/ folder, run mvn compile, then copy the pom.xml.

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?

Pushing artifacts to registries Medium
A. Inside the project's pom.xml under the <repository> tag.
B. As plaintext arguments passed to the mvn deploy command.
C. In the src/main/resources/credentials.properties file.
D. In the developer's local ~/.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?

Dependency scope Medium
A. runtime
B. test
C. provided
D. compile

40 A CI/CD pipeline executes the command mvn clean deploy. How does Maven process this command?

validate, compile, test, package, verify, install, deploy Medium
A. It runs the clean lifecycle, then runs only the deploy phase of the default lifecycle.
B. It runs the clean phase, then sequentially executes all default lifecycle phases starting from validate up to and including deploy.
C. It runs the clean phase simultaneously with the deploy phase using multithreading.
D. It bypasses 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?

Version conflicts & resolution Hard
A. Lib D (version 2.0), because Maven uses the 'nearest definition' rule, and the path to version 2.0 is shorter (depth 2 vs depth 3).
B. The build will fail with a dependency conflict error unless <dependencyManagement> is explicitly used to resolve it.
C. Lib D (version 2.0), because Lib B was declared first in the POM, triggering the 'first declaration wins' rule.
D. Lib D (version 1.0), because Maven prefers the oldest stable version to ensure backward compatibility.

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?

Using dependency Management Hard
A. Version 1.0 for Project A, but Module B will fail to compile due to ambiguity.
B. Version 1.0, because the BOM imported in <dependencyManagement> takes absolute precedence over local declarations.
C. Version 2.0, because direct dependency declarations override versions managed in <dependencyManagement>, and this override is inherited.
D. The build fails because Module B must explicitly specify a version when a conflict exists in the parent.

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?

Parent POM Hard
A. The plugin executes, but only if the child module has a <packaging>pom</packaging> configuration.
B. The 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.
C. The build fails because the plugin in the parent POM requires an explicit <skip>false</skip> parameter to propagate to children.
D. The maven-antrun-plugin executes during the validate phase of the child module.

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?

Shade plugin (uber jar) Hard
A. Use the AppendingTransformer specifically mapped to the META-INF/spring.handlers resource.
B. Use the ServicesResourceTransformer to relocate the schema packages to a shaded directory.
C. Exclude the META-INF/spring.handlers from all dependencies using the <filters> configuration.
D. Use the ManifestResourceTransformer to specify a custom main class.

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?

Dependency scope Hard
A. Runtime
B. Provided
C. Compile
D. It is completely excluded from 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?

verify Hard
A. The integration-test phase only compiles integration test sources; the actual execution occurs in the verify phase.
B. There is no difference; the maven-failsafe-plugin binds identically to both phases.
C. The integration-test phase requires an active Docker daemon, while the verify phase is used purely for offline static analysis.
D. The 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?

Maven wrapper (mvnw) Hard
A. Update the settings.xml file in the .mvn directory to include a mirror for central.
B. Add the internal repository URL to the <pluginRepositories> section of the project POM.
C. Modify the distributionUrl property inside the .mvn/wrapper/maven-wrapper.properties file.
D. Set the MAVEN_HOME environment variable on the developer's machine to point to the internal Artifactory.

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?

Maven and Docker Integration: dockerfile-maven-plugin Hard
A. By renaming the jar using the maven-assembly-plugin to app.jar and hardcoding COPY app.jar / in the Dockerfile.
B. By declaring ARG JAR_FILE in the Dockerfile and passing <buildArgs><JAR_FILE>${project.build.finalName}.jar</JAR_FILE></buildArgs> in the plugin configuration.
C. By using the Maven filtering mechanism on the Dockerfile via the maven-resources-plugin before the dockerfile-maven-plugin executes.
D. By setting <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> inside the <environmentVariables> block of the plugin.

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?

Pushing artifacts to registries Hard
A. Inside the <distributionManagement> block of the POM, using the <username> and <password> tags.
B. In the ~/.m2/settings.xml file under <servers>, mapping the <server><id> exactly to the <repository><id> specified in the POM's <distributionManagement>.
C. In a credentials.json file located in the .mvn directory.
D. By passing them as command-line arguments: mvn deploy -Drepo.username=user -Drepo.password=pass.

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?

Surefire plugin (unit testing) Hard
A. Test sources are neither compiled nor executed, completely bypassing the test-compile and test phases.
B. Unit tests execute, but their failures are ignored and do not fail the build.
C. Only classes annotated with @Ignore or @Disabled are skipped; all other unit tests are executed.
D. Test sources are compiled into the target/test-classes directory, but the actual execution of unit tests is bypassed.

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?

Problems solved by automated builds Hard
A. <maven.build.timestamp.format>
B. <project.build.outputTimestamp>
C. <reproducible.builds.enabled>
D. <maven.compiler.deterministic>

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?

Directory structure Hard
A. Set <sourceDirectory>src/main/java,src/legacy/java</sourceDirectory> in the POM's <build> section.
B. Configure the maven-compiler-plugin <includes> tag to scan the root src directory recursively.
C. Move src/legacy/java into src/main/resources and configure the <resources> tag.
D. Use the build-helper-maven-plugin with the add-source goal to register src/legacy/java as an additional source root.

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?

deploy Hard
A. The compiler plugin executes, but the surefire plugin is skipped automatically for POM projects.
B. Neither plugin executes because POM packaging explicitly unbinds the goals normally associated with compilation and testing.
C. The build fails immediately because mvn deploy cannot be executed on POM packaged projects.
D. Both plugins execute normally because deploy triggers all prior phases.

54 When resolving the Effective POM, which of the following configuration sources has the highest overriding precedence for defining a specific property value?

Project Object Model (POM) Hard
A. Properties defined directly in the project's pom.xml <properties> section.
B. Properties injected via system environment variables.
C. Properties defined in the <properties> section of the project's parent pom.xml.
D. Properties defined in an active profile within the ~/.m2/settings.xml file.

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>?

Compiler plugin Hard
A. It causes the compiler to process annotations recursively through all transitive dependencies.
B. It forces the compiler to use the system classloader (<useSystemClassLoader>true) to bypass memory limits.
C. It automatically skips the compile phase and only runs during the generate-sources phase.
D. It isolates the annotation processor so it does not leak into the project's runtime or compile classpath, strictly keeping it as a build-time tool.

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?

Dockerizing Maven-based applications Hard
A. COPY pom.xml RUN mvn dependency:go-offline COPY src RUN mvn package
B. RUN mvn clean install COPY target/app.jar ENTRYPOINT java -jar app.jar
C. COPY src and pom.xml RUN mvn clean package
D. COPY pom.xml RUN mvn compile 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?

Transitive dependencies Hard
A. Lib D is downgraded to a provided scope.
B. Lib D is entirely removed from the classpath of Project A.
C. Lib D is still included in Project A's classpath because it is transitively provided via Module C.
D. The build fails because an exclusion must be mirrored across all dependencies that provide it.

58 Which of the following restrictions applies to the import dependency scope in Maven?

Dependency scope Hard
A. It must be accompanied by the <optional>true</optional> tag.
B. It can only be used to import custom Maven plugins into the <pluginManagement> section.
C. It can only be used with <type>pom</type> and must be placed inside the <dependencyManagement> section.
D. It is functionally identical to the system scope but allows relative paths to local repositories.

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?

Build lifecycle phases Hard
A. No, because test-compile creates an isolated lifecycle fork that excludes process phases.
B. No, because process-classes is part of the default lifecycle which occurs after test-compile.
C. Yes, but only if the plugin is explicitly bound to the test profile.
D. Yes, because process-classes precedes test-compile in the default build lifecycle.

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?

Version conflicts & resolution Hard
A. Maven will resolve the lowest available version: 1.0.
B. Maven will resolve the highest upper bound: 2.5.
C. Maven will throw a DependencyResolutionException because version ranges cannot be automatically merged.
D. Maven resolves the intersection of the ranges: [1.5, 2.0).