What is the difference/relation between Maven goals and phases? How they are related to each other?
The definitions are detailed at the Maven site's page Introduction to the Build Lifecycle, but I have tried to summarize:
Maven defines 4 items of a build process:
Lifecycle
Three built-in lifecycles (aka build lifecycles): default, clean, site. (Lifecycle Reference)
Phase
Each lifecycle is made up of phases, e.g. for the default lifecycle: compile, test, package, install, etc.
Plugin
An artifact that provides one or more goals.
Based on packaging type (jar, war, etc.) plugins' goals are bound to phases by default. (Built-in Lifecycle Bindings)
Goal
The task (action) that is executed. A plugin can have one or more goals.
One or more goals need to be specified when configuring a plugin in a POM. Additionally, in case a plugin does not have a default phase defined, the specified goal(s) can be bound to a phase.
Maven can be invoked with:
clean, package)dependency:copy-dependencies):[:]: (e.g. org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile)with one or more combinations of any or all, e.g.:
mvn clean dependency:copy-dependencies package