Explore the differences and relationships between Maven goals and phases with this focused quiz. Build your expertise in Maven's tool ecosystem by distinguishing how goals and phases interact during project builds.
Which of the following options represents a phase rather than a goal in the standard Maven build lifecycle?
Explanation: Validate is a standard phase in the Maven build lifecycle, responsible for checking if the project is valid and correctly structured. The options 'install-jar', 'compile-sources', and 'generate-report' are not standard Maven phases; they sound like specific goals or incorrectly named phases, making them incorrect. Only 'validate' fits the definition of a Maven phase with standard semantics.
When you run 'mvn clean install', which of the following best describes what Maven executes?
Explanation: Running 'mvn clean install' makes Maven execute all the phases in the clean lifecycle and then all phases up to and including 'install' in the default lifecycle, with any goals attached to each phase. It does not mean only the 'install' goal is executed, nor does it execute just a single goal or literally every goal in the project. The process follows the defined order of phases and their attached goals.
If you explicitly execute a standalone goal, like 'mvn dependency:tree', what does Maven do regarding lifecycle phases?
Explanation: When an explicit goal such as 'dependency:tree' is run, Maven executes that specific goal and does not invoke any related lifecycle phases. Running all phases up to 'verify' or 'install' only occurs when a phase is targeted, not with a standalone goal. Saying Maven skips the requested goal is incorrect because it actually executes it.
What best describes the relationship between goals and phases in Maven's build lifecycle?
Explanation: In Maven, goals are tied to phases so that when a phase runs, any goals bound to it are executed as well. The other options are not correct: phases are not attached to goals, they are not entirely independent, and phases are not limited to reporting. Only the correct answer describes the key relationship.
Suppose a developer creates a custom goal and binds it to the 'verify' phase. When will this custom goal be executed during a typical Maven build?
Explanation: Binding a goal to the 'verify' phase causes it to run whenever that phase or any subsequent phase is executed, since Maven processes all previous phases in order. Calling 'validate' directly does not get as far as 'verify', so the goal wouldn't run. The custom goal is not always executed first, and attaching it to 'deploy' is unrelated to its phase binding.