简体   繁体   中英

heroku fails to pick gradle-wrapper and correct java version

I have added system.properties with java.runtime.version=1.7 and created an application in heroku to run a spring mvc war file using jetty

anadi$ heroku apps:create gogreen
Creating gogreen... done, stack is cedar
http://gogreen.herokuapp.com/ | git@heroku.com:gogreen.git
Git remote heroku added

anadi$ cat system.properties 
java.runtime.version=1.7

anadi$ cat Procfile 
web: java $JAVA_OPTS -jar build/libs/jetty-runner.jar --port $PORT build/libs/*.war

git shows files added to index

anadi$ git ls-files gradle/
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties

however deployment fails

  1. Heroku does not pick correct JDK version
  2. Heroku does not find the Gradle Main class

here's the error log from heroku

anadi$ git push heroku master
Initializing repository, done.
Counting objects: 368, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (178/178), done.
Writing objects: 100% (368/368), 192.45 KiB | 52.00 KiB/s, done.
Total 368 (delta 148), reused 353 (delta 140)

-----> Gradle app detected
-----> Installing OpenJDK 1.6... done
-----> Building Gradle app...
       WARNING: The Gradle buildpack is currently in Beta.
-----> executing ./gradlew stage
       Exception in thread "main" java.lang.NoClassDefFoundError: org/gradle/wrapper/GradleWrapperMain
       Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
       Could not find the main class: org.gradle.wrapper.GradleWrapperMain. Program will exit.
 !     Failed to build app

 !     Push rejected, failed to compile Gradle app

To git@heroku.com:gogreen.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:gogreen.git'

I fixed same problem by pushing gradle wrapper files to heroku master.

Inside your gradle project run wrapper: gradle wrapper , which creates gradle/ directory and gradlew file. Commit and push those together with your code and then it should start working.

If wrapper task is not found add the following to the build.gradle

task wrapper(type: Wrapper) {
    gradleVersion = '1.6'
}

On git push heroku master you should see Downloading https://services.gradle.org/distributions/gradle-1.6-bin.zip in the console log, like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM