I have a Spring Boot REST API locally.
It is successfully generating the.war file locally when I run mvn clean package.
Now I want to deploy it to Heroku.
These are the steps I've done.
Uploded the code to a github respository. Let's say \myrestapi.
Opened a terminal to run Heroku CLI commands
Logged in heroku
heroku login
Ran command to create the app on heroku
heroku create myrestapi
This command didn't work. Got the message saying the name "myrestapi" already existed.
So I changed the name to something else. Let's say "cl-myrestapi":
heroku create cl-myrestapi
It ran successfully.
Ran command to create the free postgreSQL database on heroku:
heroku addons:create heroku-postgresql:hobby-dev
Git push
git push heroku main
This starts downloads successfully.
But then generates the following error:
remote: [INFO] BUILD FAILURE
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] Total time: 14.653 s
remote: [INFO] Finished at: 2021-02-19T18:43:12Z
remote: [INFO] ------------------------------------------------------------------------
remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-
compile) on project myrestapi: Fatal error compiling: invalid target release: 11 -> [Help 1]
remote: [ERROR]
remote: [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote: [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote: [ERROR]
remote: [ERROR] For more information about the errors and possible solutions, please read the following artic
les:
remote: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
remote:
remote: ! ERROR: Failed to build app with Maven
remote: We're sorry this build is failing! If you can't find the issue in application code,
remote: please submit a ticket so we can help: https://help.heroku.com/
remote:
remote: ! Push rejected, failed to compile Java app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: e11a85238783f54ee30765ba4f8a55354930be
09
remote: !
remote: ! We have detected that you have triggered a build from source code with version e11a85238783f54ee30765ba4f
8a55354930be09
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to cl-myrestapi.
remote:
To https://git.heroku.com/cl-myrestapi.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cl-myrestapi.git'
Why am I getting this error since it is building successfully locally?
There are only two differences I can see:
The need to have a different project name on heroku (see step 4 above)
Application.properties is different.
This is my original application.properties (that runs locally).
spring.datasource.url=jdbc:postgresql://localhost:5432/myrestapi
spring.datasource.username=xxx
spring.datasource.password=yyy
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
This is the updated application.properties (being uploaded to heroku)
spring.datasource.url=${JDBC_DATASOURCE_URL}
spring.jpa.hibernate.ddl-auto=update
UPATE: Noted that when the git push heroku main
command is executed, at the begining it says "Installing jdk 1.8", while I'm using version 11.
So that seems to be the issue.
To solve that I tried to add a System.properties file at the root with the following line:
java.runtime.version=11
But didn't solve.
pom.xml
<properties>
<java.version>11</java.version>
</properties>
Check Java compiler
in settings and make sure that project-byte-code-version
and target-byte-code-version
have set 11.
pom.xml
file.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.