Monday, October 03, 2011

Recipe#8: Setting Up Parent Maven Project In Eclipse

Whenever you create Maven projects, a best practice is to start with a parent project from which child modules will inherit. The parent POM defines global settings and doesn't itself produce a deliverable. Child modules would include the deliverables, project documentation (user guides and API docs), libraries (if this is a dependency for other projects), etc. It eases maintenance and extensibility tremendously.

This recipe assumes you have Java (see recipe#2), Maven2 (see recipe#6),  and Eclipse (see recipe#3) configured.

In Eclipse:
* File > New > Other. Select Maven | Maven Project [Next]. Use default workspace location [Next]. Select "maven-archetype-quickstart" [Next]. Provide archetype parameters [Finish].
* Update the POM, providing #properties, #description, #licenses, #organization and #developers information, and plugin information for the compiler and surefire (test) plugins. Notice that #packaging ought to be pom.


<?xml version="1.0" encoding="UTF-8"?>
<project ...>
    <modelVersion>4.0.0</modelVersion>
   
    <groupId>com.strive</groupId>
    <artifactId>geldzin2</artifactId>
    <packaging>pom</packaging>
    <version>0.1-SNAPSHOT</version>
   
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.6</jdk.version>
    </properties>
   
    <name>Geldzin2</name>
    <description>
        An online personal financial management application.
    </description>
   
    <licenses>
         <license>
              <name>The Apache Software License, Version 2.0</name>
              <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
              <distribution>repo</distribution>
        </license>
    </licenses>
   
    <organization>
        <name>Strive Consulting, LLC</name>
        <url>http://www.strive-ltd.com</url>
      </organization>

    <developers>
          <developer>
            <id>prideafrica</id>
            <name>Jubz Madagascar</name>
            <organization>Strive Consulting, LLC</organization>
            <organizationUrl>http://www.strive-ltd.com</organizationUrl>
            <roles>
                <role>Architect</role>
                <role>Developer</role>
            </roles>
          </developer>
    </developers>
   
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>${jdk.version}</source>
                        <target>${jdk.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.9</version>
                </plugin>           
            </plugins>
        </pluginManagement>
    </build>
</project>