我正在尝试部署我一直在研究Heroku的Grails 3应用程序,但是我遇到了build.gradle文件的问题我认为。
以下命令在本地运行:
./gradlew stage
heroku local web
然后我可以在http://localhost:5000/
看到我的Grails应用程序部署的第一部分显示它执行我的阶段任务。但后来,它抱怨无法找到舞台任务。
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中,并且还填充了proc文件。
当我在项目的根目录中运行./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
对我做错了什么的想法?
答案 0 :(得分:0)
我遇到了同样的问题,可以通过运行以下命令来解决
heroku config:set GRADLE_TASK="build"
git push heroku master
您可以检查以下链接
https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku
答案 1 :(得分:0)
我正在构建一个没有测试的 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")
}
答案 2 :(得分:0)
我遇到这个问题是因为我是从 master
或 main
以外的本地分支进行部署。
有关详细信息,请参阅 Heroku 文档上的 Deploying from a branch besides main,特别是:
<块引用>如果要从本地存储库的非 main
分支(例如 testbranch
)将代码部署到 Heroku,请使用以下语法确保将其推送到远程的主分支:
git push heroku testbranch:main
就我而言,我正在一个单独的分支上测试与 Heroku 的集成。我的项目已经有一个有效的 build.gradle
并且与这里的原始问题一样,我能够成功地运行 ./gradlew stage
和 heroku local
,没有任何问题(因为他们正在访问更新的 {{1} } 在我当地的分支机构)。但是当我推送到 Heroku 时,我使用了命令 build.gradle
,这导致了臭名昭著的:
git push heroku master