为什么heroku构建会因gradle和spring boot而失败?

时间:2017-08-22 12:19:20

标签: java spring heroku gradle plugins

我试图为Spring启动和gradle设置基本工作区。 一切都在本地和travis中完美运行,但在heroku构建失败。我不认为问题出在实际代码中,而是在配置中。

以下是github.

中的项目
build.gradle

plugins {
    id 'java'
    id 'maven'
    id 'jacoco'
    id 'org.springframework.boot' version '1.5.3.RELEASE'
}

group = 'org.karlin'
version = '0.1.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

bootRepackage {
    mainClass = 'gramise.Gramise'
}

repositories {
    maven {
        url("https://plugins.gradle.org/m2/")
    }
}

dependencies {
    compile("com.google.code.gson:gson")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.postgresql:postgresql")
    compile("org.apache.commons:commons-dbcp2")
    compile("com.h2database:h2")
    testCompile(group: 'org.springframework.boot', name: 'spring-boot-
    starter-test', version:'1.5.3.RELEASE') {
        exclude(module: 'commons-logging')
    }
    testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.2.0'
}

task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean

有heroku构建日志

-----> Gradle app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Gradle Wrapper...
       WARNING: Your application does not have it's own gradlew file.
-----> Building Gradle app...
-----> executing ./gradlew build
       Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.pom
       Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-tools/1.5.3.RELEASE/spring-boot-tools-1.5.3.RELEASE.pom
       Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.pom
       Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.pom
       Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.pom
       Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.jar
       Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.jar
       Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.jar
       Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar

       FAILURE: Build failed with an exception.

       * What went wrong:
       org/gradle/api/plugins/JavaPlugin
       > org.gradle.api.plugins.JavaPlugin

       * Try:
       Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

       BUILD FAILED

2 个答案:

答案 0 :(得分:0)

您需要将gradlew检入Git。

WARNING: Your application does not have it's own gradlew file.

因为你没有这样做,所以Heroku使用的是Gradle的旧版本。

答案 1 :(得分:0)

如果其他人遇到此问题,则修复此问题

我在build.gradle中添加了buildscript

buildscript {
    ext {
        springBootVersion = '1.5.3.RELEASE'
    }
    repositories {
        mavenCentral()
        maven { url 'https://repo.spring.io/libs-snapshot' }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

现在一切正常,感谢您的帮助。