Maven Notes

This is post describing how maven works. The example pom.xml is from Apache Mahout project at http://mahout.apache.org

  • General description

Maven is a system for building a project.

  1. It manages the dependency of the projects. It can grab dependencies from a central repository, called maven central. In addition, it is also possible to install a local repository for local dependencies (possibly jars).
  2. It automatically sets up the lay out of the folders. In fact, the project directory can be created with commands. The layout of the project directory consists of src, target and a few folders.
  3. The various aspects of a maven project can be set through a pom.xml file.

  • Build Sequence
    • The default Maven build consists of several stages executed in a linear order (LIFECYCLE). A lot of the operations are declared during a specific stage. The default sequence is the following

To prevent generated sources from being generated, first in the LIFECYCLE, we can see that

generate-sources generate any source code for inclusion in compilation.

So it is generated before compile. So I changed the <phase> tag from “generate-sources” to “install”. And instead of using “mvn clean –SkipTests install” command, I use “mvn compile” for two reasons

  1. Clean will remove all source files, forcing mahout math source files to be generated again
  2. Compile will only execute default LIFECYCLE up to the stage of  “compile” and will not proceed to “install” stage.

Original tags inside trunk/math/pom.xml

<plugin>

<groupId>org.apache.mahout</groupId>

<artifactId>mahout-collection-codegen-plugin</artifactId>

<executions>

<execution>

<phase>generate-sources</phase>

<goals>

<goal>generate</goal>

</goals>

…..

modified version

<plugin>

<groupId>org.apache.mahout</groupId>

<artifactId>mahout-collection-codegen-plugin</artifactId>

<executions>

<execution>

<phase>install</phase>

<goals>

<goal>generate</goal>

</goals>

…..

  • Pom.xml
    • General
      • groupId seems to be related to the namespace of the library???
      • Artifact Id is the name of the jar file without version and .jar extenstion. For example, for hadoop-core-1.0.3.jar artifactId is hadoop-core
      • Version is the number after artifact Id, in the example of hadoop, it seems to be 1.0.3
      • Scope is well introduced in the web page “Introduction to maven dependencies”
  • Info about the entire project

<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.mahout</groupId>

<artifactId>mahout</artifactId>

<version>0.8-SNAPSHOT</version>

  • A pom file can indicate a parent

<parent>

<groupId>org.apache</groupId>

<artifactId>apache</artifactId>

<version>9</version>

</parent>

  • Dependencies

<dependency>

<groupId>org.apache.hadoop</groupId>

<artifactId>modified-hadoop-core</artifactId>

<version>1.0.3</version>

<scope>compile</scope>

</dependency>

  • Build Phases and goals

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

The build process is made up of several phases. Within each phase, there are finer grained tasks called goals.

<Generate> is a goal. <Execution> tag allows you to run the same goal multiple times with different configuration if needed.

Advertisements
This entry was posted in Tools. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s