Home > Blockchain >  I am trying automatic deploy to Heroku using GitHub actions for java Gradle app (SpringBoot) but get
I am trying automatic deploy to Heroku using GitHub actions for java Gradle app (SpringBoot) but get

Time:07-04

Getting this error: Error: Command failed: git push heroku main:refs/heads/main --force

.yml file for GitHub Actions

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/[email protected] # 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"

At first GitHub branch was set to master. I thought there could be a issue with it so renamed it to main and changed the branch. But still the issue was same. Before deployment everything goes good in GitHub actions build but during build it gets rejected and shows the error.

Procfile

web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/demo-0.0.1-SNAPSHOT.jar

Code run while it is deploying using github actions

Run akhileshns/[email protected]
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'

Screenshot for build using GitHub actions. enter image description here

CodePudding user response:

This has nothing to do with anything except your requirements. Here is the actual error, right in the output you quoted:

remote:        * What went wrong:        
remote:        Execution failed for task ':compileJava'.        
remote:        > invalid source release: 17        

(Why Java 17 is invalid here is a different question that you can ask, but see, e.g., Execution failed for task ':compileJava'. > invalid source release: 1.7 first.)

  • Related