【问题标题】:Deploy my Gradle (Spring Boot) app in Heroku在 Heroku 中部署我的 Gradle (Spring Boot) 应用程序
【发布时间】:2023-11-05 23:09:01
【问题描述】:

我有一个带有以下 build.gradle 文件的 gradle + spring boot 应用程序:

buildscript {
    ext {
        springBootVersion = '2.0.0.BUILD-SNAPSHOT'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'teambuilting'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-actuator-docs')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.data:spring-data-rest-hal-browser')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-web-services')
    compile('org.springframework.boot:spring-boot-starter-data-mongodb')

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

但是,当我尝试在 Heroku 中部署我的主分支时,我收到以下错误:

-----> Failed to detect set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/gradle.tgz
More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
 !     Push failed

我在 Buildpacks 中添加了 heroku/gradle。我还缺少什么?

【问题讨论】:

    标签: heroku github gradle spring-boot


    【解决方案1】:

    您必须在仪表板中定义项目使用 Gradle 的 buildpack。在 build.gradle 中,必须添加这个任务:

    task stage {
        dependsOn build
    }
    

    并创建一个 Procfile 来指示 Heroku 构建您的软件后的后续步骤。

    胡安·安东尼奥

    【讨论】:

    • 嗨 jabrena,我应该在 Procfile 中添加什么?
    • 您可以将此示例用作指导:github.com/jabrena/winter-games-game1/blob/v0.1.6/Procfile web: java -Dserver.port=$PORT -jar build/libs/YOUR_JAR_NAME.jar
    • 我按照你说的做了,但我还是有同样的问题,可能是因为我的应用程序在一个文件夹中造成的吗?这里有我的 git repo github.com/manuelarte/TeamBuilting.git
    • 是的,除了你还有一个 .openshift 文件夹。尝试将内容移动到根目录。
    最近更新 更多