Grails 3 和 Heroku - 找不到阶段任务

Posted

技术标签:

【中文标题】Grails 3 和 Heroku - 找不到阶段任务【英文标题】:Grails 3 and Heroku - stage task not found 【发布时间】:2016-12-04 07:28:22 【问题描述】:

我正在尝试将我一直在开发的 Grails 3 应用程序部署到 Heroku,但我的 build.gradle 文件存在问题我认为

以下命令在本地工作:

./gradlew stage
heroku local web

然后我可以在http://localhost:5000/ 看到我的 Grails 应用程序

部署的第一部分显示它执行我的阶段任务。但是后来又报找不到stage任务。

remote: -----> Gradle app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Building Gradle app...
remote:        WARNING: The Gradle buildpack is currently in Beta.
remote: -----> executing ./gradlew stage
remote:        Downloading https://services.gradle.org/distributions/gradle-2.13-all.zip

我在部署期间收到以下错误:

remote:  !     ERROR: Failed to run Gradle!
remote:        It looks like your project does not contain a 'stage' task, which Heroku needs in order
remote:        to build your app. Our Dev Center article on preparing a Gradle application for Heroku
remote:        describes how to create this task:
remote:        https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
remote:        
remote:        If you're stilling having trouble, please submit a ticket so we can help:
remote:        https://help.heroku.com
remote:        
remote:        Thanks,
remote:        Heroku
remote: 
remote:  !     Push rejected, failed to compile Gradle app.

但是,我已按照https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku 的指示,将阶段任务添加到我的 build.gradle 并填充了一个 procfile。

当我在项目的根目录中运行 ./gradlew 任务时,阶段任务确实显示在“其他任务”下的列表中。

Other tasks
-----------
assetClean
assetPluginPackage
cleanIdeaWorkspace
console
dependencyManagement
mergeTestReports
pathingJar
pathingJarCommand
schemaExport
shell
stage
urlMappingsReport
wrapper

这是我的 build.gradle:

buildscript 
    ext 
        grailsVersion = project.grailsVersion
    
    repositories 
        mavenLocal()
        maven  url "https://repo.grails.org/grails/core" 
    
    dependencies 
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
        classpath "org.grails.plugins:hibernate4:5.0.10"
    


version "0.1"
group "paxdata"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"

ext 
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion


repositories 
    mavenLocal()
    maven  url "https://repo.grails.org/grails/core" 


dependencyManagement 
    imports 
        mavenBom "org.grails:grails-bom:$grailsVersion"
    
    applyMavenExclusions false


dependencies 
    compile group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.6'
    compile 'org.grails.plugins:spring-security-core:3.1.1'
    compile 'org.grails.plugins:quartz:2.0.9'
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
    compile 'com.github.jsimone:webapp-runner:8.0.30.2'


assets 
    minifyJs = true
    minifyCss = true


task wrapper(type: Wrapper) 
    gradleVersion = gradleWrapperVersion


task stage() 
    dependsOn clean, war

tasks.stage.doLast() 
    delete fileTree(dir: "build/distributions")
    delete fileTree(dir: "build/assetCompile")
    delete fileTree(dir: "build/distributions")
    delete fileTree(dir: "build/libs", exclude: "*.war")

war.mustRunAfter clean

task copyToLib(type: Copy) 
    into "$buildDir/server"
    from(configurations.compile) 
        include "webapp-runner*"
    


stage.dependsOn(copyToLib)

这是我的 Procfile 的内容:

web: cd build ; java $JAVA_OPTS -Dgrails.env=prod -jar ../build/server/webapp-runner-*.jar --expand-war --port $PORT libs/*.war

对我做错了什么有什么想法吗?

【问题讨论】:

我遇到了同样的问题,我最终做的是直接在仪表板上更改配置 (dashboard.heroku.com)。在 Deploy 选项卡中,默认使用的部署方法是 Heroku Git,所以我将其更改为 Github。我知道这不是正确的解决方案,但至少现在有效。 【参考方案1】:

和我一样的问题,通过运行以下命令解决

heroku config:set GRADLE_TASK="build" git push heroku master

您可以查看以下链接 https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku

【讨论】:

我设置为配置变量,它解决了我的问题,谢谢。【参考方案2】:

我正在构建一个没有测试的 jar:build -x test

所以git push heroku master 在使用后工作: heroku config:set GRADLE_TASK="build -x test"

// build.gradle.kts

tasks.jar 
    manifest 
        attributes(mapOf("Main-Class" to application.mainClass))
    
    from(configurations.runtimeClasspath.get().map  f -> if (f.isDirectory) f else zipTree(f) )
    archiveFileName.set("cats-app.jar")


【讨论】:

【参考方案3】:

我遇到了这个问题,因为我是从 mastermain 以外的本地分支进行部署的。

有关详细信息,请参阅 Heroku 文档上的 Deploying from a branch besides main,具体而言:

如果您想从本地存储库的非main 分支(例如,testbranch)将代码部署到 Heroku,请使用以下语法确保将其推送到远程的主分支:

git push heroku testbranch:main


就我而言,我正在一个单独的分支上测试与 Heroku 的集成。我的项目已经有一个有效的build.gradle 并且与这里的原始问题一样,我成功地运行./gradlew stageheroku local 没有任何问题(因为他们正在访问我本地分支上更新的build.gradle)。但是当我推送到 Heroku 时,我使用的是命令 git push heroku master,这导致了臭名昭著的:

FAILURE: Build failed with an exception.
remote:        
remote:        * What went wrong:
remote:        Task 'stage' not found in root project 'build_96411775'.
...
ERROR: Failed to run Gradle!
remote:        It looks like your project does not contain a 'stage' task, which Heroku needs in order
remote:        to build your app. Our Dev Center article on preparing a Gradle application for Heroku
remote:        describes how to create this task:
remote:        https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
remote:        
remote:        If you're stilling having trouble, please submit a ticket so we can help:
remote:        https://help.heroku.com
remote:        
remote:        Thanks,
remote:        Heroku
remote: 
remote:  !     Push rejected, failed to compile Gradle app.
remote: 
remote:  !     Push failed

【讨论】:

以上是关于Grails 3 和 Heroku - 找不到阶段任务的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Heroku 上部署我的 Grails 3 应用程序

找不到类“League\Flysystem\AwsS3v3\AwsS3Adapter”(Laravel + Heroku)

找不到 grails /login/impersonate 页面

UnhandledPromiseRejectionWarning:错误:找不到模块“tailwindcss”heroku 错误

grails - 找不到域类

如何关闭我的 heroku 应用程序?