Utilizing the Build Life Cycle

In Chapter 2, Maven was described as a framework that coordinates the execution of its plugins in a well-defined way or process, which is actually Maven’s default build life cycle. Maven’s default build life cycle will suffice for a great number of projects without any augmentation – but, of course, projects will have different requirements and it is sometimes necessary to augment the default Maven life cycle to satisfy these requirements.

For example, Proficio has a requirement to generate Java sources from a model. Maven accommodates this requirement by allowing the declaration of a plugin, which binds itself to a standard phase in Maven’s default life cycle, the generate-sources phase.

Plugins in Maven are created with a specific task in mind, which means the plugin is bound to a specific phase in the default life cycle, typically. In Proficio, the Modello plugin is used to generate the Java sources for Proficio’s data model. If you look at the POM for the proficio-model you will see the plugins element with a configuration for the Modello plugin:

<project>
    <parent>
        <groupId>com.exist.mvnbook.proficio</groupId>
        <artifactId>proficio</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>proficio-model</artifactId>
    <packaging>jar</packaging>
    <name>Proficio Model</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.modello</groupId>
                <artifactId>modello-maven-plugin</artifactId>
                <version>1.0-alpha-5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <version>1.0.0</version>
                    <packageWithVersion>false</packageWithVersion>
                    <model>src/main/mdo/proficio.mdo</model>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

This is very similar to the declaration for the maven-compiler-plugin that you saw in Chapter 2, but here you see an additional executions element. A plugin in Maven may have several goals, so you need to specify which goal in the plugin you wish to run, by specifying the goal in the executions element.

Thank you for requesting a Maestro evaluation! This is our passion, and we want you to be successful. Please let us know how we may help!

Please enter your name, company email address and phone, and we will send you a link to your pre-built hosted evaluation within minutes.






I have read and agree to the Terms and Conditions.