Sunday, December 26, 2010

Apache Maven-What is a POM?

The fundamental unit of work in Maven is POM, Project Object Model. It is a XML file containing the project and configuration details used by Maven to build the project. When executing a task, Maven looks for the POM in the current directory to get needed configuration information such as project dependencies, the plugins, goals and the build profiles. POM contains other information such as project version, description, developers and mailing lists.
The Super POM is Maven's default POM. All POMs we create extend the Super POM and Super POM is inherited by the POMs. Minimum requirements for a POM are the project root, modelVersion, groupId, artifactId, version. Here is a example of a POM file with minimum requirements.

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

If the configuration details are not specified, Maven will use their defaults.  Here, with the minimum requirements, repositories are not defined. Therefore, when it is built, it will inherit the repositories configuration from Super POM.

If we want to add an another artifact to our project, my-app, it will be something like this.

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-module</artifactId>
  <version>1</version>
</project>

If we want to make the my-app project the parent of newly created artifact, we have to edit the newly created artifact module's pom file as below to include the parent's section.

<project>
  <parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-module</artifactId>
  <version>1</version>
</project>

No comments:

Post a Comment