This is a Heroku buildpack for Java apps. It uses Maven 3.2.5 to build your application and OpenJDK 8u20 to run it (by default).
The buildpack will detect your app as Java if it has a
pom.xml file in its root directory. It will use Maven to execute the build defined by your
pom.xml and download your dependencies. The
.m2 folder (local maven repository) will be cached between builds for faster dependency resolution. However neither the mvn executable or the .m2 folder will be available in your slug at runtime.
For more information about using Java and buildpacks on Heroku, see these Dev Center articles:
system.properties file in the root of your project directory and set
$ ls Procfile pom.xml src $ echo "java.runtime.version=1.7" > system.properties $ git add system.properties && git commit -m "Java 7" $ git push heroku master ... -----> Heroku receiving push -----> Fetching custom language pack... done -----> Java app detected -----> Installing OpenJDK 1.7... done ...
system.properties file also allows for
(regardless of whether you specify a
java.runtime.version entry). For example:
Supported versions of Maven include 3.0.5, 3.1.1 and 3.2.5. You can request new
versions of Maven by submitting a pull request against
There are three config variables that can be used to customize the Maven execution:
MAVEN_CUSTOM_GOALS: set to
clean installby default
MAVEN_CUSTOM_OPTS: set to
These variables can be set like this:
$ heroku config:set MAVEN_CUSTOM_GOALS="clean package" $ heroku config:set MAVEN_CUSTOM_OPTS="--update-snapshots -DskipTests=true"
Other options are available for defining custom a
To make changes to this buildpack, fork it on Github. Push up changes to your fork, then create a new Heroku app to test it, or configure an existing app to use your buildpack:
# Create a new Heroku app that uses your buildpack heroku create --buildpack <your-github-url> # Configure an existing Heroku app to use your buildpack heroku config:set BUILDPACK_URL=<your-github-url> # You can also use a git branch! heroku config:set BUILDPACK_URL=<your-github-url>#your-branch
For example if you want to have maven available to use at runtime in your application, you can copy it from the cache directory to the build directory by adding the following lines to the compile script:
for DIR in ".m2" ".maven" ; do cp -r $CACHE_DIR/$DIR $BUILD_DIR/$DIR done
This will copy the local maven repo and maven binaries into your slug.
Commit and push the changes to your buildpack to your Github fork, then push your sample app to Heroku to test. Once the push succeeds you should be able to run:
$ heroku run bash
$ ls -al
and you'll see the
.maven directories are now present in your slug.
Licensed under the MIT License. See LICENSE file.
Copy the snippet above into CLI.