我在本地主机上构建了一个几乎可以部署的应用程序,我的下一步开发是准备部署它。因此,我尝试将其部署在Heroku上,但当我尝试将代码推送到Heroku时,它试图构建它,我在-----> executing ./gradlew build -x check
的过程中遇到错误。当我尝试在本地主机上运行相同的命令时,它工作得很好。因此,我不确定我做错了什么,以及Heroku需要如何设置应用程序。
这是应用程序的构建日志:
-----> Building on the Heroku-22 stack
-----> Determining which buildpack to use for this app
-----> Gradle app detected
-----> Spring Boot detected
-----> Installing OpenJDK 1.8... done
-----> Building Gradle app...
-----> executing ./gradlew build -x check
Downloading https://services.gradle.org/distributions/gradle-7.6.1-bin.zip
...........10%............20%...........30%............40%............50%...........60%............70%............80%...........90%............100%
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.6.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'RnR'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.0.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.0
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6.1' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.0 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
! ERROR: Failed to run Gradle!
We're sorry this build is failing. If you can't find the issue in application
code, please submit a ticket so we can help: https://help.heroku.com
You can also try reverting to the previous version of the buildpack by running:
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version
Thanks,
Heroku
! Push rejected, failed to compile Gradle app.
! Push failed
这是我的build.gradle文件:
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'checkstyle'
}
group = 'FamilyFusion'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// Spring Boot Starters
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation:3.0.6'
// Thymeleaf Extras
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.2.1'
// File Upload
implementation 'commons-fileupload:commons-fileupload:1.5'
// Gedcom4j
implementation 'org.gedcom4j:gedcom4j:4.0.1'
// JSON
implementation 'org.json:json:20230618'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Development Tools
developmentOnly 'org.springframework.boot:spring-boot-devtools'
// Database Connector
runtimeOnly 'com.mysql:mysql-connector-j'
// Testing
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
checkstyle {
toolVersion = 8.40
maxWarnings = 0
ignoreFailures = true
}
tasks.withType(Checkstyle).configureEach {
reports {
xml.required = true
html.required = true
}
}
tasks.named('test') {
useJUnitPlatform()
}
这是我的application.properties文件:
#### Database ####
spring.datasource.url=jdbc:mysql://localhost:3306/roots_and_recipes
spring.datasource.username=*****
spring.datasource.password=******
spring.jpa.database-platform=MySQL
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
#### SSL ####
server.port=8443
server.ssl.enabled=true
server.ssl.key-store=classpath:FamilyFusionSecurity.p12
server.ssl.key-store-password=******
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=FamilyFusionSecurity
server.ssl.protocol=TLS
#### Spring Mail ####
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=****
spring.mail.password=******
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
我知道目前数据库是本地主机,但我想看看我是否可以首先在Heroku上构建应用程序,然后将其正确连接到基于云的数据库(计划使用JawsDB MySQL的免费版本)
1条答案
按热度按时间m3eecexj1#
您正在应用的Sping Boot Gradle插件版本要求您至少使用Java 17运行Gradle。
在本地运行Java 17,一切都很好。
但是在Heroku上,您使用的Java 8不受您使用的Sping Boot Gradle插件的支持。
您需要将Heroku配置为至少使用Java 17运行Gradle构建。
如https://devcenter.heroku.com/articles/java-support#specifying-a-java-version中所述,创建一个文件
system.properties
,例如在其中设置java.runtime.version=17
。