8 Customizing the Build Process with Maven POM Inheritance

Oracle provides a set of common parent Project Object Models (POMs) to enable easy customization of the build process for all projects targeted at a particular product, runtime environment, or for all projects targeted at Oracle Fusion Middleware.

Each of the Oracle-provided Maven archetypes have their parent POM set to an Oracle-provided common parent specific to the target runtime environment that the archetype is for, such as WebLogic Server and Coherence. The common parent POMs, one per product or target runtime environment, in turn have their parent POM set to an Oracle Fusion Middleware common parent.

The common POMs and Oracle-provided archetypes form the following inheritance hierarchy:

If you want to customize your build process, for example, setting some default properties, setting up default settings for a particular plug-in, or defining Maven profiles, then you can add your definitions to the appropriate parent POM. For example, if you add definitions to com.oracle.weblogic:wls-common:12.1.3-0-0, all projects associated with this parent are affected, which includes all projects that you have created from the WebLogic Maven archetypes (unless you modify their parents) and projects that you have created manually.

This enables you to minimize the number of settings needed in each project POM. For example, if you are going to deploy all of builds to the same test server, then you can provide the details for the test server by adding the appropriate build, plug-ins, and plug-in section for com.oracle.weblogic:wls-maven-plugin:12.1.3-0-0 as shown in the following example of a customized parent WebLogic POM:

<project xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.oracle.weblogic.archetype</groupId>
  <artifactId>wls-common</artifactId>
  <version>12.1.3-0-0</version>
  <packaging>pom</packaging>
  <name>wls-common</name>
  <parent>
    <groupId>com.oracle.maven</groupId>
    <artifactId>oracle-common</artifactId>
    <version>12.1.3-0-0</version>
  </parent>
  <build>
    <plugins>
      <plugin>
        <groupId>com.oracle.weblogic</groupId>
        <artifactId>wls-maven-plugin</artifactId>
        <version>12.1.3-0-0</version>
        <executions>
          <execution>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <user>weblogic</user>
              <password>welcome1</password>
              <verbose>true</verbose>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <middlewareHome>/home/oracle/fmwhome</middlewareHome>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Similarly, if you want to affect all projects targeted at any Oracle Fusion Middleware runtime, then you should place your customizations in com.oracle.maven:oracle-common:12.1.3-0-0.

If you are using a shared internal repository, then after you customize the parent POMs, publish them into your shared Maven repository or repositories.

To see how these customizations are brought into your projects, you can use the following command, from your project's directory, to see the full POM that will be used to build your project:

mvn help:effective-pom

If you want to define more than one set of shared properties in the parent POM, for example, one set for your test environment, and one for your QA environment, Oracle encourages you to explore the use of Maven profiles. For more information, see:

http://www.sonatype.com/books/mvnref-book/reference/profiles.html

Profiles enable you to switch various settings on for a particular build by setting a command line argument, or based on the presence or absence of various properties in the POM.