Build Maven Applications

Using Apache Maven, you can automate your build process and download dependencies, as defined in the POM file:

  1. Upload the Maven POM files to the project Git repository.
  2. Open the job’s configuration page.
  3. In the Git tab, add the Git repository where you uploaded the build files.
  4. Click the Steps tab.
  5. From Add Step, select Maven.
  6. In Goals, enter Maven goals, or phases, along with their options. By default, clean and install goals are added.

    For more information about Maven goals, see the Maven Lifecycle Reference documentation at http://maven.apache.org.

  7. In POM file, enter the Maven POM file name and path, relative to the workspace root. The default value is pom.xml at the Git repository root.
  8. If necessary, specify the Advanced Maven Settings:
    Action How To
    Use a private repository for builds Select the Use Private Repository check box.

    You may want to use it to make sure that other Maven build artifacts don’t interfere with the artifacts of this job’s builds. When a build runs, it creates a Maven repository .maven/repo directory in the build executor workspace. Remember selecting this option consumes more storage space of the workspace.

    Use a private temporary directory for builds. Select the Use Private Temp Directory check box.

    You may want to use it to create a temporary directory for artifacts or temporary files. When a build runs, it creates a .maven/tmp directory in the workspace. The temporary files may consume large amount of storage, so, remember to clean up the directory regularly.

    Work offline and don’t access remote Maven repositories Select the Offline check box.
    Activate Maven profiles In Profiles, enter a list of profiles, separated by commas.

    For more information about Maven profiles, see the Maven documentation at http://maven.apache.org.

    Set custom properties In Properties, enter custom system properties in the key=value format. Specify each property on its own line.

    Tip:

    Don't surround properties that have multi-word values, like key2=say hello, with single or double quotes. Multi-word property assignments will be automatically wrapped with double quotes.

    Also, notice that arguments, which are generated for the mvn command, have an extra space in them between "-D" and the argument, like this:

    mvn ... -D key1=value1 -D "key2=say hello" ...

    When a build runs, the properties are passed to the build executor in the standard way (for example, -Dkey1=value1 -Dkey2=value2) without the extra spaces.

    Include build parameters in the Properties list Leave checked (default setting) to include all build parameters in the Properties list.

    Deselect to stop automatically adding the parameters to the list.

    Set the Maven verbosity level From Verbosity, select the level.

    You may want to use it to set the verbosity of the Maven log output to the build log.

    Set the checksum mode From Checksum, select the mode.

    You may want to use it to set the check-sum validation strictness when the build downloads artifacts from the remote Maven repositories.

    Set handling of the SNAPSHOT artifacts From Snapshot, select the mode.
    Include other Maven projects to the reactor In Projects, enter the comma or space separated list of Maven project jobs to include in the reactor. The reactor is a mechanism in Maven that handles multi-module projects. A project job can be specified by [groupId]:artifactId or by its relative path.
    Resume a Maven project from the reactor In Resume From, enter the Maven job project name from where you would like to resume the reactor. The Maven job project can be specified by [groupId]:artifactId or by its relative path.
    Set the failure handling mode From Fail Mode, select the mode.

    You may want to use it to set how the Maven build proceeds in case of a failure.

    Set the Make-like reactor mode From Make Mode, select the mode. You may want to use it enable Make-like build behavior.
    Configure the reactor threading model In Threading, enter the value for experimental support for parallel builds. For example, a value of 3 indicates three threads for the build.
    Pass parameters to Java VM In JVM Options, enter the parameters. The build passes the parameters as MAVEN_OPTS.
  9. Click Save.

Use the WebLogic Maven Plugin

The WebLogic server includes a Maven plugin that you can use to perform various deployment operations against the server, such as deploy, redeploy, and update. The plugin is available in the VB Studio build executor. For more information about how to use the WebLogic Maven plugin, see Fusion Middleware Deploying Applications to Oracle WebLogic Server in Oracle Fusion Middleware Online Documentation Library.

When a build runs, the build executor creates an empty Maven repository in the workspace.

Note:

Make sure that your build VM template includes the WebLogic Server (WLS) software bundle. For example, the Oracle JDeveloper Studio 12 software bundle includes the JDeveloper Studio 12.2.1.3 (or 12.2.1.4) software.
To install the WebLogic plugin every time a build starts, in the job configuration, add a Unix Shell command to install the plugin and then deploy it:
  1. Open the job’s configuration page.

  2. Click the Steps tab.

  3. From Add Step, select Unix Shell.

  4. In Script, enter this command:

    # Use sync to install deps
    mvn install:install-file \
        -DpomFile=`find $MIDDLEWARE_HOME -name "oracle-maven-sync*.pom"` \
        -Dfile=`find $MIDDLEWARE_HOME -name "oracle-maven-sync*.jar"`
    mvn com.oracle.maven:oracle-maven-sync:push \
        -DoracleHome=${MIDDLEWARE_HOME}
    
    # Add additional arguments for deployment
    mvn com.oracle.weblogic:weblogic-maven-plugin:deploy
  5. Click Save.

Upload to or Download Artifacts from the Project Maven Repository

To upload artifacts to the Maven repository, you'll use the distributionManagement snippet in the POM file. To download artifacts from the Maven repository, use the repositories snippet in the POM file:

  1. To upload a build artifact to the Maven repository, copy the distributionManagement snippet of the project’s Maven repository and add it to the POM file:
    1. In the left navigator, click Maven Maven.
    2. On the right side of the page, click Browse.
    3. In the Artifact Details section, expand Distribution Management.
    4. In the Maven tab, click Copy Copy to clipboard to copy the <distributionManagement> code snippet to the clipboard.
    5. Open the POM file of your project in a code editor (or a text editor) and paste the contents of the clipboard under the <project> element:
  2. To download an artifact from the Maven repository, use the repositories snippet of the project’s Maven repository:
    1. In the left navigator, click Maven Maven.
    2. On the right side of the page, click Browse.
    3. In the Artifact Details section, expand Distribution Management.
    4. In the Maven tab, copy the <repository> element of the Distribution Management to the clipboard.
    5. Open the POM file of your project in a code editor (or a text editor) and paste the <repository> element in the<repositories> element under <project>:
      <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/maven-v4_0_0.xsd">
      	<modelVersion>4.0.0</modelVersion>
      	<groupId>com.example.employees</groupId>
      	<artifactId>employees-app</artifactId>
      	<packaging>war</packaging>
      	<version>0.0.1-SNAPSHOT</version>
      	<name>employees-app Maven Webapp</name>
      	<url>http://maven.apache.org</url>
      	
      	<repositories>
      	  <repository>
                 <id>Demo_repo</id>
                 <name>Demo Maven Repository</name>
                 <url>http://developer.us2.oraclecloud.com/profile/my-org/s/my-org_demo_12345/maven/</url>
               </repository>
      	</repositories>
      .
      .
      .
      </project>
  3. Save the file, commit it to the Git repository, and then push the commit.
  4. Configure the job to add a Maven step and add the required Maven goals:

    Description of devcs_build_job_mavengoals.png follows
    Description of the illustration devcs_build_job_mavengoals.png

    Tip:

    Use the deploy goal to upload Maven artifacts to the project’s Maven repository.
  5. If you want to view build information for an artifact uploaded to the Maven repository with a build job or pipeline, make sure that the build executor template you select from the Software catalog in the Software tab includes the latest Maven and Gradle versions.
  6. Run a build of the job.

    Note:

    You don't have to provide the credentials in settings.xml to access the project’s Maven repository when you run a build. Build jobs have full access to the project’s Maven repository for uploads and downloads.
  7. If you configured the job to upload artifacts to the project’s Maven repository, after the build is successful, verify the artifacts in the Maven page:
  8. If you selected a build executor template that includes Maven and Gradle from the Software catalog in the Software tab, you can view build information for the artifact: