得到这个错误:错误:命令失败:git push heroku main:refs/heads/main——force
。GitHub Actions的yml文件
name: Java CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- name: Build with Gradle
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee
with:
arguments: build
- uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: "all-books-store" #Must be unique in Heroku
heroku_email: "mail-id-here"
branch: "main"
最初GitHub分支被设置为master。我想可能会有问题,所以把它重命名为main并更改了分支。但问题还是一样的。在部署之前,GitHub actions构建中一切正常,但在构建期间,它被拒绝并显示错误。
Procfile
web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/demo-0.0.1-SNAPSHOT.jar
使用github actions部署时运行的代码
Run akhileshns/heroku-deploy@v3.12.12
Created and wrote to ~/.netrc
Successfully logged into heroku
› Warning: Our terms of service have changed:
Added git remote heroku
› https://dashboard.heroku.com/terms-of-service
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Gradle app detected
remote: -----> Spring Boot detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew build -x check
remote: Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
remote: ...........10%...........20%...........30%...........40%...........50%...........60%...........70%...........80%...........90%...........100%
remote: To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
remote: Daemon will be stopped at the end of the build
remote: > Task :compileJava FAILED
remote:
remote: FAILURE: Build failed with an exception.
remote:
remote: * What went wrong:
remote: Execution failed for task ':compileJava'.
remote: > invalid source release: 17
remote:
remote: * Try:
remote: > Run with --stacktrace option to get the stack trace.
remote: > Run with --info or --debug option to get more log output.
remote: > Run with --scan to get full insights.
remote:
remote: * Get more help at https://help.gradle.org
remote:
remote: BUILD FAILED in 24s
remote: 1 actionable task: 1 executed
remote:
remote: ! ERROR: Failed to run Gradle!
remote: We're sorry this build is failing. If you can't find the issue in application
remote: code, please submit a ticket so we can help: https://help.heroku.com
remote: You can also try reverting to the previous version of the buildpack by running:
remote: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
remote:
remote: Thanks,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Gradle app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to all-books-store.
remote:
To https://git.heroku.com/all-books-store.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/all-books-store.git'
Unable to push branch because the branch is behind the deployed branch. Using --force to deploy branch.
(If you want to avoid this, set dontuseforce to 1 in with: of .github/workflows/action.yml.
Specifically, the error was: Error: Command failed: git push heroku main:refs/heads/main
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Gradle app detected
remote: -----> Spring Boot detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew build -x check
remote: Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
remote: ...........10%...........20%...........30%...........40%...........50%...........60%...........70%...........80%...........90%...........100%
remote: To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
remote: Daemon will be stopped at the end of the build
remote: > Task :compileJava FAILED
remote:
remote: FAILURE: Build failed with an exception.
remote:
remote: * What went wrong:
remote: Execution failed for task ':compileJava'.
remote: > invalid source release: 17
remote:
remote: * Try:
remote: > Run with --stacktrace option to get the stack trace.
remote: > Run with --info or --debug option to get more log output.
remote: > Run with --scan to get full insights.
remote:
remote: * Get more help at https://help.gradle.org
remote:
remote: BUILD FAILED in 24s
remote: 1 actionable task: 1 executed
remote:
remote: ! ERROR: Failed to run Gradle!
remote: We're sorry this build is failing. If you can't find the issue in application
remote: code, please submit a ticket so we can help: https://help.heroku.com
remote: You can also try reverting to the previous version of the buildpack by running:
remote: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
remote:
remote: Thanks,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Gradle app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to all-books-store.
remote:
To https://git.heroku.com/all-books-store.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/all-books-store.git'
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Gradle app detected
remote: -----> Spring Boot detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew build -x check
remote: Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
remote: ...........10%...........20%...........30%...........40%...........50%...........60%...........70%...........80%...........90%...........100%
remote: To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
remote: Daemon will be stopped at the end of the build
remote: > Task :compileJava FAILED
remote:
remote: FAILURE: Build failed with an exception.
remote:
remote: * What went wrong:
remote: Execution failed for task ':compileJava'.
remote: > invalid source release: 17
remote:
remote: * Try:
remote: > Run with --stacktrace option to get the stack trace.
remote: > Run with --info or --debug option to get more log output.
remote: > Run with --scan to get full insights.
remote:
remote: * Get more help at https://help.gradle.org
remote:
remote: BUILD FAILED in 23s
remote: 1 actionable task: 1 executed
remote:
remote: ! ERROR: Failed to run Gradle!
remote: We're sorry this build is failing. If you can't find the issue in application
remote: code, please submit a ticket so we can help: https://help.heroku.com
remote: You can also try reverting to the previous version of the buildpack by running:
remote: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
remote:
remote: Thanks,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Gradle app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 04b91247a117524163405aa40742f4bd84afb3fc
remote: !
remote: ! We have detected that you have triggered a build from source code with version 04b91247a117524163405aa40742f4bd84afb3fc
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: !
Error: Error: Command failed: git push heroku main:refs/heads/main --force
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Gradle app detected
remote: -----> Spring Boot detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew build -x check
remote: Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
remote: ...........10%...........20%...........30%...........40%...........50%...........60%...........70%...........80%...........90%...........100%
remote: To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
remote: Daemon will be stopped at the end of the build
remote: > Task :compileJava FAILED
remote:
remote: FAILURE: Build failed with an exception.
remote:
remote: * What went wrong:
remote: Execution failed for task ':compileJava'.
remote: > invalid source release: 17
remote:
remote: * Try:
remote: > Run with --stacktrace option to get the stack trace.
remote: > Run with --info or --debug option to get more log output.
remote: > Run with --scan to get full insights.
remote:
remote: * Get more help at https://help.gradle.org
remote:
remote: BUILD FAILED in 23s
remote: 1 actionable task: 1 executed
remote:
remote: ! ERROR: Failed to run Gradle!
remote: We're sorry this build is failing. If you can't find the issue in application
remote: code, please submit a ticket so we can help: https://help.heroku.com
remote: You can also try reverting to the previous version of the buildpack by running:
remote: $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
remote:
remote: Thanks,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Gradle app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 04b91247a117524163405aa40742f4bd84afb3fc
remote: !
remote: ! We have detected that you have triggered a build from source code with version 04b91247a117524163405aa40742f4bd84afb3fc
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 all-books-store.
remote:
To https://git.heroku.com/all-books-store.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/all-books-store.git'
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 all-books-store.
remote:
To https://git.heroku.com/all-books-store.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/all-books-store.git'
使用GitHub操作构建的截图。输入图片描述
这与您的需求无关。下面是实际的错误,就在你引用的输出中:
remote: * What went wrong:
remote: Execution failed for task ':compileJava'.
remote: > invalid source release: 17
(为什么Java 17是无效的这里是一个不同的问题,你可以问,但看到,例如,执行失败的任务':compileJava'。比;无效的源代码版本:1.7优先)