Heroku Spring Boot不会构建Jar

时间:2016-05-31 15:38:20

标签: java spring heroku gradle spring-boot

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

Gradle buildpack仍在" beta"虽然它没有让我失望。

的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
}

1 个答案:

答案 0 :(得分: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")
    }
}