3

Quite new in maven. By reading document of maven at official website, I know in the default lifeCycle, there are 21 phases including validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install and deploy.

But when I see Built-in Lifecycle Bindings, I found that there is no plugin goals binding to phases like validate, initialize, verify, etc.
So if I run command mvn package, are phases without plugin goals going to be executed?
Or plugins goals for these phases are fixed and we do not have control of them so there is no need to write them in the document. Every time these phases like validate, initialize, verify, etc. will be executed automatically.

Frank Kong
  • 1,010
  • 1
  • 20
  • 32

1 Answers1

0

First yes there are no plugins bound to the phases validate, initialize and verify by default (and some other phases as well).

If you run mvn package all phases will be executed but if there is no plugin bound to a phase you can't see it. If you run package phase all the phases including package phase itself will be executed from the beginning validate, initialize, generate-sourcesand so on...

Sometimes it is useful to bind plugins to phases like initialize. This is the case for example for the build-number-maven-plugin.

Phases before verify like pre-integration-test, integration-test and post-integration-test are useful to run integration tests which can be handled by maven-failsafe-plugin. The unit tests are handled by the maven-surefire-plugin.

Phases like generate-sources are often used by source generating plugins like jaxb2-maven-plugin or others like annotation processor generation plugins...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for your answer. So you mean when I run mvn package, phase initialize would also be run but nothing is done in this phase because no plugin goals bound to it? – Frank Kong Oct 09 '16 at 15:28
  • 1
    @Frankie It's more that no plugins are bound to `initialize` in the default lifecycle. But, your POM could use a plugin goal that binds to it by default and so it would execute. You could also have another lifecycle that has a binding to it. – Tunaki Oct 09 '16 at 18:25
  • @Tunaki OK, I got it. Maven only execute plugin goals. Because no default plugin goals binds to phase initialize in default life cycle, I cannot see this phase in default life cycle. If I has a pom that has a plugin binding to initialize, this plugin would be executed so that I can see the phase. Phase is a just a abstraction to indicate order. Right? – Frank Kong Oct 09 '16 at 19:07