What are Maven goals and phases and what is their difference?

前端 未结 8 1267
时光说笑
时光说笑 2020-11-27 23:51

What is the difference/relation between Maven goals and phases? How they are related to each other?

8条回答
  •  佛祖请我去吃肉
    2020-11-28 00:28

    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:

    1. Lifecycle

      Three built-in lifecycles (aka build lifecycles): default, clean, site. (Lifecycle Reference)

    2. Phase

      Each lifecycle is made up of phases, e.g. for the default lifecycle: compile, test, package, install, etc.

    3. 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)

    4. 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:

    1. a phase (e.g clean, package)
    2. : (e.g. dependency:copy-dependencies)
    3. :[:]: (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
    

提交回复
热议问题