Lifecycle bindings

Under the discussion of the default lifecycle, we briefly touched upon the concept of lifecycle bindings. The default lifecycle is defined without any associated lifecycle bindings, while both the clean and site lifecycles are defined with bindings. The standard Maven lifecycles and their associated bindings are defined under the file META-INF/plex/components.xml of MAVEN_HOME/lib/maven-core-3.2.3.jar.

Here is the definition of the default lifecycle without the associated plugin bindings:

<component>
  <role>org.apache.maven.lifecycle.Lifecycle</role>
  <implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
  <role-hint>default</role-hint>
  <configuration>
    <id>default</id>
    <phases>
      <phase>validate</phase>
      <phase>initialize</phase>
      <phase>generate-sources</phase>
      <phase>process-sources</phase>
      <phase>generate-resources</phase>
      <phase>process-resources</phase>
      <phase>compile</phase>
      <phase>process-classes</phase>
      <phase>generate-test-sources</phase>
      <phase>process-test-sources</phase>
      <phase>generate-test-resources</phase>
      <phase>process-test-resources</phase>
      <phase>test-compile</phase>
      <phase>process-test-classes</phase>
      <phase>test</phase>
      <phase>prepare-package</phase>
      <phase>package</phase>
      <phase>pre-integration-test</phase>
      <phase>integration-test</phase>
      <phase>post-integration-test</phase>
      <phase>verify</phase>
      <phase>install</phase>
      <phase>deploy</phase>
    </phases>
  </configuration>
</component>

The components.xml file, which is also known as the component descriptor, describes the properties required by Maven to manage the lifecycle of a Maven project. The role element specifies the Java interface exposed by this lifecycle component and defines the type of the component. All the lifecycle components must have org.apache.maven.lifecycle.Lifecycle as role. The implementation tag specifies the concrete implementation of the interface. The identity of a component is defined by the combination of the role and the role-hint elements. The role-hint element is not a mandatory element; however, if we have multiple elements of the same type, then we must define a role-hint element. Corresponding to Maven lifecycles, the name of the lifecycle is set as the value of the role-hint element.

The clean lifecycle is defined with an associated plugin binding to the clean goal of maven-clean-plugin. The plugin binding is defined under the element default-phases. The code is as follows:

<component>
  <role>org.apache.maven.lifecycle.Lifecycle</role>
  <implementation>org.apache.maven.lifecycle.Lifecycle
  </implementation>
  <role-hint>clean</role-hint>
  <configuration>
    <id>clean</id>
    <phases>
      <phase>pre-clean</phase>
      <phase>clean</phase>
      <phase>post-clean</phase>
    </phases>
    <default-phases>
      <clean>
        org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean 
      </clean>
    </default-phases>
  </configuration>
</component>

The site lifecycle is defined with the associated plugin bindings to the site and the site-deploy goals of maven-site-plugin. The plugin bindings are defined under the element default-phases. The code is as follows:

<component>
  <role>org.apache.maven.lifecycle.Lifecycle</role>
  <implementation>org.apache.maven.lifecycle.Lifecycle
  </implementation>
  <role-hint>site</role-hint>
  <configuration>
    <id>site</id>
    <phases>
      <phase>pre-site</phase>
      <phase>site</phase>
      <phase>post-site</phase>
      <phase>site-deploy</phase>
    </phases>
    <default-phases>
      <site>
        org.apache.maven.plugins:maven-site-plugin:2.0.1:site
      </site>
      <site-deploy>
        org.apache.maven.plugins:maven-site-plugin:2.0.1:deploy
      </site-deploy>
    </default-phases>
  </configuration>
</component>

Finally, let's have a look at how the jar plugin binding for the default lifecycle is defined. The following component element defines a plugin binding to an existing lifecycle and the associated lifecycle is defined under the configuration/lifecycles/lifecycle/id element:

<component>
  <role>
    org.apache.maven.lifecycle.mapping.LifecycleMapping
  </role>
  <role-hint>jar</role-hint>
  <implementation>
    org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
  </implementation>
  <configuration>
    <lifecycles>
      <lifecycle>
        <id>default</id>
        <phases>
          <process-resources>
             org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources
          </process-resources>
          <compile>
            org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
          </compile>
          <process-test-resources>
            org.apache.maven.plugins:maven-resources-plugin:2.4.3:testResources
          </process-test-resources>
          <test-compile>
            org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile
          </test-compile>
          <test>
            org.apache.maven.plugins:maven-surefire-plugin:2.5:test
          </test>
          <package>
            org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar
          </package>
          <install>
            org.apache.maven.plugins:maven-install-plugin:2.3.1:install
          </install>
          <deploy>
            org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
          </deploy>
        </phases>
      </lifecycle>
    </lifecycles>
  </configuration>
</component>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.157.197