Heroku Spring Boot 不构建 Jar

Posted

技术标签:

【中文标题】Heroku Spring Boot 不构建 Jar【英文标题】:Heroku Spring Boot doesn't build Jar 【发布时间】:2016-09-29 17:20:58 【问题描述】:

我正在部署到 Heroku,我还没有真正改变任何东西,现在 Heroku 没有创建 Jar。

Gradle buildpack 仍处于“测试版”,尽管它从未让我失望。

Heroku

remote: -----> Using set buildpack heroku/gradle
remote: -----> Gradle app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Installing Gradle Wrapper...
remote:        WARNING: Your application does not have it's own gradlew file.
remote:        We'll install one for you, but this is a deprecated feature and
remote:        in the future may not be supported.
remote: -----> Building Gradle app...
remote:        WARNING: The Gradle buildpack is currently in Beta.
remote: -----> executing ./gradlew stage
remote:        :api:compileJavaNote: Some input files use unchecked or unsafe operations.
remote:        Note: Recompile with -Xlint:unchecked for details.
remote:        
remote:        :api:processResources
remote:        :api:classes
remote:        :api:war
remote:        :api:bootRepackage
remote:        :api:assemble
remote:        :api:cleanNode
remote:        :api:stage
remote:        BUILD SUCCESSFUL

请注意缺少:api:jar,但在本地它就在那里..

:api:compileJava UP-TO-DATE
:api:processResources UP-TO-DATE
:api:classes UP-TO-DATE
:api:jar
:api:findMainClass
:api:startScripts
:api:distTar
:api:distZip
:api:war
:api:bootRepackage
:api:assemble
:api:cleanNode
:api:stage

BUILD SUCCESSFUL

Gradle 是直截了当的。

apply plugin: "java"
apply plugin: "war"
apply plugin: "spring-boot"

task cleanNode 
    doLast 
        // clean up files we no longer need in the slug
        delete '../node_modules'
        delete '../html/bower_components'
    


// used by Heroku
task stage 
    dependsOn cleanNode, assemble

【问题讨论】:

您能检查一下您的build.gradle 是否已签入Git 吗?然后你能通过运行git push heroku HEAD:master来检查你推送的分支是否正确吗? 这是百分百正确的。 这是否意味着文件签入并且您正在部署正确的分支,但您仍然遇到问题? 对,抱歉没有澄清。我run bashcatbuild.gradle。一切看起来都很好。我想知道我是否必须使用包装器。 明智的做法是使用包装器。它将确保您在本地和 Heroku 上运行相同版本的 Gradle。 【参考方案1】:

我必须使用 Gradle Wrapper 才能使用相同的 Gradle 版本。

Heroku 使用的是 Gradle 2.10,而我使用的是 2.13。我不确定有什么区别,但这是一件好事。

正如@codefinger 所说,使用相同的版本是明智的。

作为奖励,我添加了一些内容来清理 Heroku Slug 以减小大小。

// used by Heroku
task stage 
    dependsOn assemble

    doLast 
        // https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku#using-grails-3
        // this still leaves around empty folders, but what are you going to do?
        delete fileTree(dir: "build", exclude: "libs")
        delete fileTree(dir: "build/libs", exclude: "*.jar")
    

【讨论】:

以上是关于Heroku Spring Boot 不构建 Jar的主要内容,如果未能解决你的问题,请参考以下文章

在heroku上部署spring boot应用程序的问题

Spring Boot应用程序在Heroku代码= H10上崩溃

Spring Boot + Angular 2 Heroku 部署

Heroku H14(没有运行 Web 进程)+ Spring-boot

Heroku 无法部署 Java 11 Spring Boot App [重复]

源码分析:通过Spring Boot构建一个购物车微服务 | 云原生应用开发系列6