Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 336
Donato Amasa Avatar asked Dec 22 '20 06:12

Donato Amasa


2 Answers

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.

like image 82
Donato Amasa Avatar answered Sep 24 '22 00:09

Donato Amasa


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.

like image 43
rain Avatar answered Sep 23 '22 00:09

rain