Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Heroku Cloud Native Java Buildpack

CI Registry

Heroku's official Cloud Native Buildpack for Java applications.

Table of Contents

How it works

This buildpack will install OpenJDK 8 (Configuration: OpenJDK Version) and builds your app with Maven. It requires either:

The buildpack will try to figure out the required goals/tasks to run based on the framework used by your application. It will also add a process type based on the framework. If required, those features can be configured:

How it works: Maven

The buildpack will use the Maven wrapper in your app's root directory to execute the build defined by the POM and download your dependencies. If the application does not use Maven wrapper, it will install Maven and use that instead.

The local Maven repository (.m2 folder) will be cached between builds for dependency resolution. However, neither the mvn executable (if installed) nor the .m2 folder will be available in your container at runtime.

Configuration

Procfile

A Procfile is a text file in the root directory of your application that defines process types and explicitly declares what command should be executed to start your app. Your Procfile will look something like this for Spring Boot:

web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/demo-0.0.1-SNAPSHOT.jar

OpenJDK

OpenJDK Version

By default, the latest OpenJDK 8 release will be installed. You can configure the OpenJDK version your application needs. The buildpack tries to determine the required version in the following order:

system.properties

You can specify a Java version by adding a Java properties file called system.properties to the root directory of your application. The value of the java.runtime.version key specifies the required OpenJDK version:

java.runtime.version=15

Supported major versions are 1.7, 1.8, 11, 13, and 15. The buildpack will always install the latest release of the requested major version.

Environment variable: BP_JVM_VERSION

You can use the same major version strings as in the system.properties file. In addition, it is allowed to append .* to a major version (i.e. 11.* for OpenJDK 11). This ensures compatibility with the Spring Boot Plugin.

Customizing the JDK

There are some cases where files need to be bundled with the JDK in order to expose functionality in the runtime JVM. For example, the inclusion of a custom certificate authority (CA) store is common. To handle such cases, this buildpack will copy files designated by the app in a .jdk-overlay folder into the JDK's directory structure.

Adding custom certificates

You may also need to add custom certificates to the JDK’s cacerts. You may start with the keystore in your local JDK or download the base Heroku keystore. Add the custom certificate with:

keytool -import -keystore cacerts -file custom.cer

You may be prompted for a password. The default password is changeit. You may then include the keystore in the slug by placing it in the .jdk-overlay/jre/lib/security/ directory of your app’s repository (or .jdk-overlay/lib/security/ for Java 11 and higher).

Customizing runtime JVM flags

To set JVM flags during runtime, the JAVA_TOOL_OPTIONS environment variable can be used. It is directly supported by Java and intended to augment a command line in environments where the command-line cannot be accessed or modified. Since it is automatically picked up by Java, you do not need to include it in your Procfile command.

Maven

Maven Version

We encourage users to use Maven wrapper to set the required Maven version for their applications.

If you cannot or do not want to use Maven wrapper, you can specify the Maven version for your application by adding (or extending) a Java properties file called system.properties in the root directory of your application.

The maven.version key determines the Maven version that is installed. Currently, supported versions are 3.2.5, 3.3.9, 3.5.3, and 3.6.2. The default is 3.6.2.

maven.version=3.5.3

Customizing Maven execution

There is a set of environment variables that can be used to customize the Maven execution.

Environment variable: MAVEN_CUSTOM_GOALS

Allows overriding the Maven goals used during the build process. The default goals are clean install.

Environment variable: MAVEN_CUSTOM_OPTS

Allows overriding Maven options used during the build process. The default options are -DskipTests.

Environment variable: MAVEN_JAVA_OPTS

Allows overriding the Java options for the Maven process during build. The default Java options are -Xmx1024m. See Customizing runtime JVM flags on how to set Java options during runtime.

Using a custom Maven settings file

A Maven settings.xml file defines values that configure Maven execution in various ways. Most commonly, it is used to define a local repository location, alternate remote repository servers, and authentication information for private repositories.

When a file named settings.xml is present in the root directory of the application, the buildpack will automatically use it to configure Maven at build time.

Environment variable: MAVEN_SETTINGS_PATH

If you do not want the settings.xml file in the root directory or if you intend to frequently change between different setting configurations, you may prefer to put a settings file in a custom location. The buildpack provides this capability with the MAVEN_SETTINGS_PATH environment variable.

Environment variable: MAVEN_SETTINGS_URL

When the MAVEN_SETTINGS_URL config variable is defined, the buildpack will download the file at the given location and use it to configure Maven.

License

See LICENSE file.