Super POM

Any POM file can point to its parent POM. If the parent POM element is missing, then there is a system-wide POM file that is automatically treated as the parent POM file. This POM file is well known as the super POM. Ultimately, all the application POM files get extended from the super POM. The super POM file is at the top of the POM hierarchy, and it is bundled inside MAVEN_HOME/lib/maven-model-builder-3.2.3.jar - org/apache/maven/model/pom-4.0.0.xml. In Maven 2, this was bundled inside maven-2.X.X-uber.jar. All the default configurations are defined in the super POM file. Even the simplest form of a POM file will inherit all the configurations defined in the super POM file. Whatever configuration you need to override, you can do it by redefining the same section in your application POM file. The following lines of code show the super POM file configuration, which comes with Maven 3.2.3:

<project>
  <modelVersion>4.0.0</modelVersion>

The Maven central is the only repository defined under the repositories section. It will be inherited by all the Maven application modules. Maven uses the repositories defined under the repositories section to download all the dependent artifacts during a Maven build. The following code snippet shows the configuration block in pom.xml, which is used to define repositories:

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

Plugin repositories define where to find Maven plugins. We'll be discussing about Maven plugins in Chapter 5, Maven Plugins. The following code snippet shows the configuration related to plugin repositories:

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>

The build configuration section includes all the information required to build a project:

  <build>
    <directory>${project.basedir}/target</directory>
    <outputDirectory>${project.build.directory}/classes
    </outputDirectory>
    <finalName>${project.artifactId}-${project.version}
    </finalName>
    <testOutputDirectory>${project.build.directory}/test-classes
    </testOutputDirectory>
    <sourceDirectory>${project.basedir}/src/main/java
    </sourceDirectory>
    <scriptSourceDirectory>${project.basedir}/src/main/scripts
    </scriptSourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/java
    </testSourceDirectory>

    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources
        </directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>${project.basedir}/src/test/resources
        </directory>
      </testResource>
    </testResources>

    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>

  </build>

The reporting section includes the details of report plugins, which are used to generate reports that will be later displayed on the site generated by Maven. The super POM only provides a default value for the output directory. The code is as follows:

  <reporting>
    <outputDirectory>${project.build.directory}/site
    </outputDirectory>
  </reporting>

The following code snippet defines the default build profile. When no profiles are defined at the application level, this will get executed. We will be talking about profiles in Chapter 9, Best Practices:

  <profiles>
    <profile>
      <id>release-profile</id>

      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>

      <build>
        <plugins>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
              <updateReleaseInfo>true</updateReleaseInfo>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  
</project>

The following figure shows an abstract view of the super POM file, with the key configuration elements:

Super POM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.134.154