Maven Tips on OpenShift

This post will describe some of the tips for using Maven with your OpenShift applications

Defaults

Goals/Phases/Options: The default maven goals are “clean package -Popenshift -DskipTests“. This default set of goals will:

clean: remove all files generated by the previous build

package: Execute the build lifecycle up to creating the deployment archive(s) (e.g. jar, war, ear)

-Popenshift: Execute the “openshift” build profile as defined in pom.xml

-DskipTests: Will not execute the project tests

MAVEN_OPTS:

The default JVM heap size is set to a ratio of the available memory available in the Gear. If hot_deploy is disabled then the maven heap size will be 75% of the Gear memory limit. If hot_deploy is enabled then the maven heap size will be 25% of the Gear memory limit. The latter is due to both the application and the maven build running concurrently within the Gear’s memory space. To override these default ratios, export MAVEN_JVM_HEAP_RATIO with the custom setting in the .openshift/action_hooks/pre_build_carttype action hook. For example: export MAVEN_JVM_HEAP_RATIO=”0.50″

Custom Goals/Phases/Options

If not using Jenkins to manage the builds: In order to override the default maven goals/phases/options export MAVEN_ARGS with the custom setting in the .openshift/action_hooks/pre_build_carttype action hook. For example: export MAVEN_ARGS=”package -Popenshift”

If using Jenkins to manage the builds: In the Jenkins console, edit the Build/Execute shell section of the Job configuration.

Custom MAVEN_OPTS

If not using Jenkins to manage the builds: In order to override the default MAVEN_OPTS export MAVEN_OPTS with the custom setting in the .openshift/action_hooks/pre_build_carttype action hook. For example: export MAVEN_OPTS=”-Xmx=512m”

If using Jenkins to manage the builds: In the Jenkins console, edit the Build/Execute shell section of the Job configuration.

Install Local Components

To install maven components that are not available in a public or accessible repository:

1) add the component archive to the root of the application’s git repo

2) add the following to the .openshift/action_hooks/pre_build

mvn install:install-file -Dfile=../../carttype/repo/filename -DgroupId=groupId -DartifactId=artifactId -Dversion=version -Dpackaging=packaging

For example:

mvn install:install-file -Dfile=../../jbossas-7/repo/caching-1.0.jar -DgroupId=org.judcon -DartifactId=caching -Dversion=1.0 -Dpackaging=jar

3) git commit and push

Custom Repositories

One or more repositories are provided via settings.xml depending on the cartridge type. Additional repositories may be added to OpenShift Online applications via the application’s pom.xml. For OpenShift Origin, the default repositories can also be modified by editing the settings.xml file(s) within the cartridge info/configuration directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>