PayPal - The safer, easier way to pay online!

[ Previous | TOC | Next ]

Building phase

Preamble

Within this tutorial you will get a detailed explanation of the maven lifecycles and how to customize them.

The lifecycles in details

We will not explain too much details here. But we will try to explain the things you may need as a php developer.

The lifecycle ordering

The lifecycle goals (you already got some of them) are depending on each other. This means: Later goals require the previous goals succeeding. For example packaging requires that testing succeeded.

Let us know look at a simplified ordering of the build lifecycle phases:

  • resources (*)
  • test
  • package
  • verify
  • install
  • deploy

(*) The standard maven documentation Differs in some way. Do not mind it. As we said we try to explain it in words a php developer understands.

resources

The very first phase you notice is the resource phase. Within our tutorial we already learned a way to customize resources on the fly (remember the filtering for version.txt). However the php-maven plugin will do both, the copying and filtering of resources into the target folders and the copying of the php sources into the target folder.

test

The testing phase will execute any test case you specified. Testing is important because it ensures at least a minimum of project quality. Of course the project quality depends on amount and quality of your test cases. There is a statement you should follow: "Writing test cases may be time consuming but you will always tune up quality and speed up the roll out because of minimum of reported bugs." But there are two more statements: "Automatic test cases do not ensure that your project is bug free but writing test cases for each bug increases the possibility that it never appears again." and "There may be a point where writing a unit test is too complex and time consuming so do only write it when there is a bug report." Find the way that best fits your needs.

package

The packaging phase will create a package. Maven manages projects always in a two-file specification. For those of you that already know maven from Java: Do not complain here. Yeah, Maven knows of managing more than two files per project but for PHP developer two files are enough. The most important file is the pom file. It contains all information such as name and version or your project. The second important file is the package. For historic reason php-maven will support multiple formats here.

Introduced in php-maven1 it will support classic zips and jars. However jar is not php-like. Php-maven2 now only supports php5 and the more php-like PHAR. So we require at least PHP 5.2.0 here. Because of bugs within PHP we recommend at least version 5.2.6. There are still some open bugs related to phar support:

Some of the bugs influence the behavior of php-maven and may cause bad performance because of workarounds. You will find some workarounds later on within the detailed explanation of the configuration options.

verify

Php-maven itself won't do anything at this phase. But you can use it to perform additional tasks right before anything is installed anywhere. Remember that we said above the later phases won't be executed if anything in previous phases fails. Some people like doing a checkstyle and let the build fail on checkstyle violations. It is good practice to do the checkstyle and other checks within the verify phase.

The install phase will copy the package and the pom into your local repository. Maven silently created a local repository for you. You already visited it because it is located in the user home at ~/.m2/repository nearby your settings.xml. This location can be manipulated but we do not explain this here. Each module and project is first copied to this location before it can be used by maven. This is important since it allows you to work offline as soon as maven got every dependency. So it is a good task to execute the following maven command on your project:

mvn clean install site stage

This command should do everything and download everything needed by your project. The site goal is discussed in another tutorial chapter related to the project documentation. The stage goal is only needed by multi project layouts. As for a single project simple remove the stage goal. Do work offline simply add the flag "--offline" at command line, for example:

mvn --offline test

Notice: Maven will fail if working in offline mode but needing something it does not find in the local repository. Adding new dependencies or build plugins, changing versions may require to be online one time to download them. Working offline means to not detect for newer versions of snapshots too.

deploy

Deploying projects means to publish them into a repository. So called it means to "install" them to become available to others. That's not the correct explanation but we will use this term. It is not important for the deploy goal where to deploy it. It simply must know the repository target/url. However it is your task to ensure that others can access this repository. The deploy task may even use another local repository in your filesystem no other developers ever see...

Add additional tasks

We will show up a checkstyle invocation to manipulate the lifecycle. As we already said this should be placed in the verify phase. Add the following to your pom.xml:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <configLocation>/var/www/projects/git/maven-php-plugin/branches/2.0-SNAPSHOT/checkstyle.xml</configLocation>
          <consoleOutput>true</consoleOutput>
          <logViolationsToConsole>true</logViolationsToConsole>
          <detail>true</detail>
          <failOnViolation>true</failOnViolation>
          <failsOnError>true</failsOnError>
          <violationSeverity>warning</violationSeverity>
        </configuration>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>
				

Of course you can use other phases too. The above configuration requires you to place your checkstyle profile at the root directory of your project.

[ Previous | TOC | Next ]