Heroku's official Cloud Native Buildpack for Java applications.
This buildpack will install OpenJDK 8 (Configuration: OpenJDK Version) and builds your app with Maven. It requires either:
- A
pom.xml
file, or one of the other POM formats supported by the Maven Polyglot plugin in the root directory of your app. See How it works: Maven for Maven specifics.
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:
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.
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
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:
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.
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.
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.
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).
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.
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
There is a set of environment variables that can be used to customize the Maven execution.
Allows overriding the Maven goals used during the build process. The default goals are clean install
.
Allows overriding Maven options used during the build process. The default options are -DskipTests
.
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.
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.
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.
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.
See LICENSE file.