Spring Boot gradle 构建失败

eko*_*eko 2 java heroku gradle spring-boot

当我尝试构建项目时,我收到此错误(在部署到 heroku 时)。这是我的第一个 Spring boot 应用程序,老实说我找不到这个问题的任何解决方案。我的Jdk是v.17

remote:        A problem occurred configuring root project 'demo'.
remote:        > Could not resolve all files for configuration ':classpath'.
remote:           > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
remote:             Required by:
remote:                 project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1
remote:              > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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' but:
remote:                  - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a library, packaged as a jar, and its dependencies declared externally:
remote:                      - 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
remote:                      - Other compatible attribute:
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
remote:                  - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a component, and its dependencies declared externally:
remote:                      - Incompatible because this component declares documentation and the consumer needed a library
remote:                      - Other compatible attributes:
remote:                          - Doesn't say anything about its target Java version (required compatibility with Java 8)
remote:                          - Doesn't say anything about its elements (required them packaged as a jar)
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
remote:                  - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 declares a library, packaged as a jar, and its dependencies declared externally:
remote:                      - 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
remote:                      - Other compatible attribute:
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
remote:                  - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
remote:                      - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 8
remote:                      - Other compatible attribute:
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
remote:                  - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
remote:                      - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 8
remote:                      - Other compatible attribute:
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
remote:                  - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a component, and its dependencies declared externally:
remote:                      - Incompatible because this component declares documentation and the consumer needed a library
remote:                      - Other compatible attributes:
remote:                          - Doesn't say anything about its target Java version (required compatibility with Java 8)
remote:                          - Doesn't say anything about its elements (required them packaged as a jar)
remote:                          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')

Run Code Online (Sandbox Code Playgroud)

编辑:

这是build.gradle文件配置。也许某些依赖项不兼容?

plugins {
    id 'java-library'
    id 'org.springframework.boot' version '3.0.1'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'


repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation group: 'com.opencsv', name: 'opencsv', version: '5.7.1'
    implementation group: 'org.modelmapper', name: 'modelmapper', version: '3.1.1'

}

tasks.named('test') {
    useJUnitPlatform()
}

Run Code Online (Sandbox Code Playgroud)

Ric*_*sta 9

如果您使用的是 InteliJ,则需要转到 File > Settings > Build, Execution, Deployment > Build Tools > Gradle 并将 Gradle JVM 更改为 17。

干杯