Sharpen your understanding of structuring, configuring, and building multi-module Maven projects. This quiz covers fundamental concepts, key practices, and typical configurations encountered in multi-module project management within the Maven build ecosystem.
In a multi-module Maven project, why is the 'packaging' type of the parent project commonly set to 'pom', as shown in a parent POM configuration?
Explanation: Setting the parent project's packaging type to 'pom' enables it to serve as a container for common configuration, dependency management, and aggregation of submodules. Unlike a runnable application, the 'pom' type cannot be executed or packaged as a JAR, so the second and third options are incorrect. The 'pom' packaging does not restrict plugin inheritance; rather, it allows sharing configuration, making the last option unsuitable.
How are submodules referenced within a multi-module Maven project’s parent POM file?
Explanation: Submodules are specified in the parent POM inside the <modules> element by listing their directories. Dependencies are used for linking libraries or jars, not for module reference, making the second option incorrect. There is no <subprojects> tag in standard Maven configuration, dismissing the third. System properties are unrelated to module structure, as reflected in the last distractor.
Which Maven command will build all modules in a multi-module project while ensuring proper inter-module dependency resolution?
Explanation: The 'mvn clean install' command triggers a clean build and installs all modules in the correct order, resolving dependencies between modules. 'mvn single-module package' would only operate on a single module, not the entire tree. There is no standard 'build-aggregate' goal or 'global-pom build' command in Maven, making those options invalid for this context.
When a submodule specifies a parent in its POM.xml, what does it typically inherit from the parent POM in a multi-module Maven project?
Explanation: Submodules inherit properties, dependencies defined in dependencyManagement, and plugin configurations from the parent POM, streamlining configuration consistency. The code from the parent is not inherited this way, so the second option is incorrect. Environment variables and repository credentials are managed outside of Maven POM inheritance, ruling out the last two distractors.
What is the main advantage of defining dependencies in a 'dependencyManagement' section within the parent POM of a multi-module Maven project?
Explanation: The 'dependencyManagement' section allows the parent to set versions and scopes centrally, so submodules can reference dependencies without repeating version numbers, making maintenance easier. However, it does not auto-download dependencies unless explicitly declared in submodules, countering the second option. Preventing duplicate classes relates to shading or packaging, not dependency management. Submodules still need to reference the dependencies by coordinate, making the last option inaccurate.