heroku无法选择gradle-wrapper并更正java版本

时间:2014-08-08 17:20:58

标签: java git heroku gradle

我已将system.properties添加到java.runtime.version=1.7并在heroku中创建了一个应用程序,以使用jetty运行spring mvc war文件

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显示添加到索引

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

然而部署失败

  1. Heroku没有选择正确的JDK版本
  2. Heroku找不到Gradle Main类
  3. 这是来自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'
    

1 个答案:

答案 0 :(得分:1)

我通过将gradle包装器文件推送到heroku master来修复了同样的问题。

在gradle项目中运行包装器:gradle wrapper,它创建gradle/目录和gradlew文件。提交并将它们与您的代码一起推送,然后它应该开始工作。

如果未找到wrapper任务,请将以下内容添加到build.gradle

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

git push heroku master上,您应该在控制台日志中看到Downloading https://services.gradle.org/distributions/gradle-1.6-bin.zip,如下所示:

-----> 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
       ................................................