This plugin is used to deploy Java applications directly to Heroku without pushing to a Git repository. This is can be useful when deploying from a CI server.
The plugin has two targets:
-
heroku:deployfor deploying standalone applications -
heroku:deploy-warfor deploying WAR files
Add the following to your pom.xml, but replace the <web> element with the command used to run your application.
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>0.3.4</version>
<configuration>
<appName>${heroku.appName}</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>Now, if you have the Heroku Toolbelt installed, run:
$ mvn heroku:deployIf you do not have the toolbelt installed, then run:
$ HEROKU_API_KEY="xxx-xxx-xxxx" mvn heroku:deployAnd replace "xxx-xxx-xxxx" with the value of your Heroku API token.
NOTE: This requires that you use <packaging>war</packaging> in your pom.xml.
Add the following to your pom.xml, but replace the <web> element with the command used to run your application.
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>0.3.4</version>
<configuration>
<appName>${heroku.appName}</appName>
</configuration>
</plugin>
</plugins>
</build>This assumes your project will generate a WAR file in the target directory. If the WAR file is located somewhere else,
you can specify this with the <warFile> configuration element. The <processTypes> element is not needed because
the plugin will determine the appropriate process type for you.
Now, if you have the Heroku Toolbelt installed, run:
$ mvn heroku:deploy-warIf you do not have the toolbelt installed or have not logged in, then run:
$ HEROKU_API_KEY="xxx-xxx-xxxx" mvn heroku:deploy-warAnd replace "xxx-xxx-xxxx" with the value of your Heroku API token.
You can execute your WAR file locally by running the following command:
$ mvn heroku:run-warThis will start the web application in a way that is very similar to how it is run on Heroku.
- Maven 3.2.x
- Java 1.7 or higher
In the <configuration> element of the plugin, you can set the JDK version like so:
<jdkVersion>1.8</jdkVersion>The default is 1.8, but 1.6 and 1.7 are valid values. The plugin will also pick up the java.runtime.version set in
your system.properties file, but the plugin configuration will take precedence.
You can set configuration variables like this:
<configVars>
<MY_VAR>SomeValue</MY_VAR>
<JAVA_OPTS>-Xss512k -XX:+UseCompressedOops</JAVA_OPTS>
</configVars>Any variable defined in configVars will override defaults and previous defined config variables.
You may set process types (similar to a Procfile):
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web>
<worker>java $JAVA_OPTS -cp target/classes:target/dependency/* Worker</worker>
</processTypes>The plugin will also pick up any process types defined in your Procfile, but the plugin configuration
will take precedence.
You can include additional directories in the slug as long as they are relative to the project root:
<includes>
<include>etc/readme.txt</include>
</includes>You can set the Heroku runtime stack like this:
<stack>cedar-14</stack>See the integration tests under maven-plugin/src/it for more examples.
Many apps, such as those built with Spring Boot, will only need a single executable JAR file in production. You can configure the plugin to deploy only this file like so:
<includeTarget>false</includeTarget>
<includes>
<include>target/my-app-1.0.jar</include>
</includes>In most real-world scenarios, you will need to deploy your application to dev, test and prod environments. There are several ways of handling this.
Use a profile for each app, and configure the plugin accordingly. For example:
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>${heroku-maven-plugin.version}</version>
<configuration>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* Main</web>
</processTypes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<configuration>
<appName>myapp-test</appName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<configuration>
<appName>myapp-prod</appName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>You can provide the application name as a system property like this:
$ mvn heroku:deploy -Dheroku.appName=myappThis solution is best when multiple developers each need their own apps.
Create a heroku.properties file in the root directory of your application and put the following code in it
(but replace "myapp" with the name of your Heroku application):
heroku.appName=myapp
Then add the file to your .gitignore so that each developer can have their own local versions of the file.
The value in heroku.properties will take precedence over anything configured in your pom.xml.
mvn heroku:dashboardopens the Dashboard for the application on Heroku.commvn heroku:eclipse-launch-configgenerates launch configurations for Eclipse IDEmvn heroku:create-slugbuilds the slug file without deploying itmvn heroku:deploy-slugdeploys a slug already created bycreate-slugordeployand deploy it. This command does not work with thedeploy-wargoal.
To run the entire suite of integration tests, use the following command:
$ mvn clean install -Pintegration-testTo run an individual integration test, use a command like this:
$ mvn clean install -Pintegration-test -Dinvoker.test=simple-deploy-test