Grails 3 and Heroku - stage task not found
Asked Answered
R

3

6

I'm trying to deploy a Grails 3 application that I've been working on to Heroku but am having issues with the build.gradle file I Think.

The following commands work locally:

./gradlew stage
heroku local web

I can then see my Grails application at http://localhost:5000/

The first part of the deploy, shows that it executes my stage task. But later on, it complains that the stage task cannot be found.

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

I receive the following error during deploy:

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.

However, I have followed the directions at https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku and have added the stage task to my build.gradle and have populated a procfile as well.

When I run ./gradlew tasks in the root of my project, the stage task does show in the list under "Other Tasks".

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

This is my 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)

This is the content of my Procfile:

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

Any thoughts on what I am doing wrong?

Roundelay answered 29/7, 2016 at 14:21 Comment(1)
I was having the same issue and what I ended up doing was to change the configuration directly on the dashboard (dashboard.heroku.com). In the Deploy tab the deployment method used by default is the Heroku Git so I changed it to Github. I know this is not the correct solution but at least is working now.Hic
L
14

same issue with me, solved by run this following command

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

You can check this following link https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku

Leyba answered 31/10, 2018 at 10:35 Comment(1)
I set as config vars and it solved my issue, thanks.Ecbatana
U
2

I ran into this issue because I was deploying from a local branch other than master or main.

See Deploying from a branch besides main on the Heroku docs for details, specifically:

If you want to deploy code to Heroku from a non-main branch of your local repository (for example, testbranch), use the following syntax to ensure it is pushed to the remote’s main branch:

git push heroku testbranch:main


In my case, I was testing integration with Heroku on a separate branch. My project already had a working build.gradle and as with the original question here, I was successfully able to run ./gradlew stage and heroku local without any issue (because they were accessing the updated build.gradle on my local branch). But when i pushed to Heroku I was using the command git push heroku master which the resulted in the infamous:

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
Ursulina answered 23/6, 2021 at 2:49 Comment(0)
M
0

I'm building a jar without tests: build -x test

So git push heroku master worked after using: 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")
}

Musgrove answered 27/12, 2020 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.