Heroku - Error during git push/deployment, The same version of this code has already been built
Asked Answered
Z

7

13

I have a problem deploying my springboot application to Heroku. After running git push heroku master, I am encountering the error below:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.350 s
[INFO] Finished at: 2020-12-22T06:33:14Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project audit: 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] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :audit
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:             31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 31199a7acec03a3cb614ebaaf6c7720cee6684bd
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 tesda8app.

I am clueless into why this error occurred. I have two remote repositories on which I push my code, one from Heroku and one in Github. I have tried the command below based from the answer from this question, Heroku: If you are developing on a branch and deploying via git you must run:

git push heroku master:main

But still the error persists. Is there any command that I could try on the Heroku CLI to solve this problem?

Zirconia answered 22/12, 2020 at 6:47 Comment(4)
That's just a warning. The actual error is above that. Please edit your question and show us the error messages above.Prosopopoeia
hi chris thank you for pointing that out. i already updated the error logsZirconia
I don't think that's the whole message. Please add all of it.Prosopopoeia
hi @Prosopopoeia ive updated the logs. that's all the error message i gotZirconia
Z
9

After some few tries, I was thinking that the cause of the problem was maybe an interrupted git push heroku master command, which was then proceeded by a re-execution of the same command, causing the error below:

remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built:             31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  ! at least twice. One common cause of this behavior is attempting to deploy         code     from a different branch.
remote:  !

So what I did was, I pushed another commit, then retried the same command git push heroku master, which resulted to a successful deployment.

Also, shoutout to RainXCat's answer and insights, now I know Heroku does not allow two git repositories on the same directory/folder.

Zirconia answered 28/12, 2020 at 1:9 Comment(1)
I was facing the same issue. Adding another commit and push to the remote server solved my problem thank you.Abloom
O
5

I was having the same error on the same day as you, I don't know if it's the answer you are looking for but I somehow solved the issue. I was making a Django-Rest-Api.

REASON

you have created two git repositories in the same folder/directory and pushed the same code into their head and somehow Heroku doesn't want you to do that. remember no two git repo on the same level.

about the git push heroku master:main thing

Heroku only deploy your code from the main/master branch so if you are pushing from other than master, you have to use it like git push heroku <new branch>:main, using :main with master is meaningless(same).

SOLUTION

option 1 (not working for me)

I don't remember exactly where I get this but you have to make a new git branch, do

git branch <new branch>
git checkout <new branch>
git add .
git commit -am "commit message"
git push heroku <new branch>:main

but it's giving the same error because you still have two git repo in your directory.

you can remove the repo like this.

rm -rf .git

I suggest you to do the experiment on a temporary copy.

option 2 (working for me)

All I did was copy all the files inside, made a new folder with a different name, pasted all files, deleted the old, and rename the new to the old one. by doing this you will have a git free directory then you can use the git init method to simply make a new repo.

here is how you should create

git init
heroku create
git add .
git commit -am "initial commit"
git push heroku master

This should resolve the error, It's solved for me so it's unlikely that I am going to work on it anymore but if my answer is not right in any manner please do tell me.

Osteal answered 24/12, 2020 at 9:43 Comment(0)
T
1

I deleted my package-lock.json file and do the following again

  1. git init
  2. git add .
  3. git commit -m ""
  4. git push heroku main

the purpose is to clear your build cache

Tape answered 25/7, 2022 at 15:52 Comment(0)
L
0

this worked for me!

git branch <new branch>
git checkout <new branch>
git add .
git commit -am "commit message"
git push heroku <new branch>:main

git push --set-upstream heroku <new branch>

this worked for me.

Linear answered 16/4, 2022 at 19:51 Comment(0)
V
0

I just made an empty commit and push again. It worked for me.

git commit --allow-empty -m 'empty commit for pushing staging environment'
git push staging master
Valer answered 10/11, 2022 at 14:27 Comment(0)
B
0

I have solved the issue by rebuilding the pipenv files: Pipfile Pipfile.lock

and released the newly added conig.in Pipfile is inconstant with the current Python version

Bohemianism answered 12/1 at 9:54 Comment(0)
C
-1

Install the Heroku CLI Download and install the Heroku CLI.

If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.

$ heroku login

Clone the repository Use Git to clone projects' source code to your local machine.

$ heroku git:clone -a project







$ cd project

Deploy your changes Make some changes to the code you just cloned and deploy them to Heroku using Git.

$ git add .
$ git commit -am "make it better"
$ git push heroku master
Cleotildeclepe answered 11/7, 2021 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.