Spring Boot Gradle app on Heroku: Unable to access jarfile

后端 未结 3 1133
無奈伤痛
無奈伤痛 2021-01-03 09:49

I have a spring boot gradle app which I could run successfully on my PC by doing:

heroku local

It can also deploy on heroku successfully wh

相关标签:
3条回答
  • 2021-01-03 09:59

    According to the documentation:

    The Gradle buildpack will automatically detect the use of the Spring Boot and Ratpack web frameworks.

    The web command should be overridden only if needed. If you're using Spring Boot, you shouldn't need to specify a Procfile at all.

    Delete it, and get your app running without further configuration.

    0 讨论(0)
  • 2021-01-03 10:04

    You don't need to modify your stage task for that.

    In your gradle.build file, make sure to give a name to your built artifact like this.

    jar {
        baseName = 'app'
        version = '0.0.1'
    }
    

    With that been done, and the following in Procfile, it should just run fine.

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

    I found that if name is not explicitly defined, heroku seems to name the artifact something like build-{buildNumber}.jar and no wonder it will never find the app.jar.

    Also, if not set already, the build pack needs to be set.

    heroku config:set GRADLE_TASK="build"
    
    0 讨论(0)
  • 2021-01-03 10:19

    I eventually found a very helpful thread here: Running Spring app built with gradle on Heroku

    Which helped me with my problem - this thread seems to be more detail than Heroku's official guide.

    You must add the following code to your build.gradle file:

    task stage(type: Copy, dependsOn: [clean, build]) {
        from jar.archivePath
        into project.rootDir
        rename {
            'app.jar'
        }
    }
    stage.mustRunAfter(clean)
    
    clean << {
        project.file('app.jar').delete()
    }
    

    Then, point your Procfile to the app.jar:

    web: java $JAVA_OPTS -jar app.jar
    
    0 讨论(0)
提交回复
热议问题