Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to build app with Maven, I can run code locally, but fail to deploy on heroku

Tags:

java

maven

heroku

This is my code in github: https://github.com/q463746583/CS4500-Assignment2 I can run it successfully in the local, but while I try to deploy the code on heroku, There is the error description:

       [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 6.0 MB/s)
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 4 source files to /tmp/build_3c4f3b86a26f6e3ae1cbe89639f79f26/target/classes
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD FAILURE
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time: 13.261 s
       [INFO] Finished at: 2019-01-24T00:47:07Z
       [INFO] ------------------------------------------------------------------------
       [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project myapp: Fatal error compiling: invalid target release: 11 -> [Help 1]
       [ERROR] 
       [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
       [ERROR] Re-run Maven using the -X switch to enable full debug logging.
       [ERROR] 
       [ERROR] For more information about the errors and possible solutions, please read the following articles:
       [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
 !     ERROR: Failed to build app with Maven
       We're sorry this build is failing! If you can't find the issue in application code,
       please submit a ticket so we can help: https://help.heroku.com/
 !     Push rejected, failed to compile Java app.
 !     Push failed
like image 789
Cvanzy Avatar asked Jan 24 '19 01:01

Cvanzy


People also ask

Can we deploy Java application on Heroku?

You can deploy any Java application on Heroku. It is not limited to JEE or other frameworks. You can deploy Java web applications packaged as WAR files using WAR deployment or you can deploy Maven based Java projects of any kind using the git versioning system.

Can I deploy Spring Boot to Heroku?

The Spring Boot model of deploying standalone applications is a great fit for Heroku. You can use either Maven or Gradle to deploy a Spring application on Heroku, but for this guide we'll assume that you're using Maven and have Maven 3 installed on your machine. To begin, create a free Heroku account.


3 Answers

As per the previous answers, creating a system.properties file, making a new commit with that change and rerunning the heroku command fixed the issue for me.

enter image description here

Also, please be mindful about the name of your branch if you're not using main as your main branch as that would require a match such as.

git push heroku master:main

or

git push heroku develop:main
like image 180
Francislainy Campos Avatar answered Sep 26 '22 22:09

Francislainy Campos


TLDR:

  1. Ensure you're using the appropriate JAVA JDK
  2. Check that your target environment from the Maven compiler is the same as your targeted Heroku JAVA runtime.
  3. If you're not using the default JAVA 8 JDK runtime environment create a system.properties file in your project specifying a different supported JAVA runtime enviroment as listed within Heroku's JAVA buildpack documentation.

I think this has to do with a mismatch between your targeted Java runtime environment on Heroku and your locally compiled code, generated from the Maven compiler, which you're trying to push to Heroku.

According to Heroku's documentation:

Heroku currently uses OpenJDK 8 to run your application by default. OpenJDK versions 9 and 7 are also available.

Other supported default versions are:

  • Java 7 - 1.7.0_181
  • Java 8 - 1.8.0_191
  • Java 9 - 9.0.4
  • Java 10 - 10.0.2
  • Java 11 - 11

So you should make sure that within your pom.xml file that your maven compiler is compiling your JAVA code to the appropriate JAVA buildpack you're targeting on Heroku. For example, below we are targeting a Java 7 runtime environment:

pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

Then you should create a system.properties file in your project if you're targeting a runtime environment other than Heroku's default JDK 1.8 runtime environment. You can do this by specifying your desired java runtime environment like such:

system.properties:

java.runtime.version=11
like image 17
Nathan Avatar answered Nov 02 '22 17:11

Nathan


I got the same error while deploying the git project in Heroku. I just changed java.version to 8 from 11 in pom.xml and it worked for me:

<properties>
    <java.version>8</java.version>
</properties>
like image 3
Abdul Waquar Avatar answered Nov 02 '22 18:11

Abdul Waquar