我有一个 Sprint Boot 项目,我在另一个系统上构建了该项目,我正尝试将其导入到 Eclipse (4.20.0) 中的新系统中,但我遇到了一些问题。这是一个 Gradle Spring Boot。我的 build.gradle 文件在下面。我在机器上安装了 JKD 16.0.1 -- Windows 10。
我已经尝试使用 Gradle buildship 和 STS 插件导入它。当我尝试 Buildship 时,它在导入预览中失败,并带有大堆栈转储,顶行:
org.gradle.tooling.BuildException: Could not fetch model of type 'GradleBuild' using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.8.3-bin.zip'.
当我尝试 Gradle STS 时,当我点击“构建模型”按钮时,我告诉我出现错误并检查日志文件。我发现其中有趣的事情是:
!ENTRY org.springsource.ide.eclipse.gradle.core 4 0 2021-06-18 17:38:25.575
!MESSAGE Could not determine java version from '16.0.1'.
!STACK 0
java.lang.IllegalArgumentException: Could not determine java version from '16.0.1'.
!MESSAGE Initialize project OrderCreate, Update preview failed due to an error in the referenced Gradle build.
!STACK 0
org.gradle.tooling.BuildException: Could not fetch model of type 'GradleBuild' using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.8.3-bin.zip'.
Caused by: org.gradle.internal.exceptions.LocationAwareException: Initialization script 'C:\Workspaces\Java\K2\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle'
Could not compile initialization script 'C:\Workspaces\Java\K2\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle'.
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during semantic analysis: Unsupported class file major version 60
java.lang.IllegalArgumentException: Unsupported class file major version 60
!ENTRY org.springsource.ide.eclipse.gradle.core 4 0 2021-06-18 17:45:56.693
!MESSAGE Could not determine java version from '16.0.1'.
!STACK 0
java.lang.IllegalArgumentException: Could not determine java version from '16.0.1'.
!MESSAGE Not properly disposed SWT resource
!STACK 0
java.lang.Error: SWT Resource was not properly disposed
!MESSAGE Not properly disposed SWT resource
!STACK 0
java.lang.Error: SWT Resource was not properly disposed
我还尝试从终端构建它以获取一些线索。这给了我“不支持的类文件主要版本 60”错误。
Could not compile settings file 'C:\Workspaces\Java\K2\OrderCreate\settings.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 60
这看起来真是一团糟。我从哪里开始解决这个问题?
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'eclipse'
id "com.diffplug.eclipse.apt" version "3.29.1"
}
group = 'com.bw'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
ext {
mapstructVersion = "1.4.2.Final"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-artemis'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
implementation("org.mapstruct:mapstruct:${mapstructVersion}")
compileOnly "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
testImplementation('de.flapdoodle.embed:de.flapdoodle.embed.mongo')
implementation 'org.springframework.boot:spring-boot-starter-websocket'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
}
test {
useJUnitPlatform()
}
来自 Gradle Buildship 的错误:
org.gradle.tooling.BuildException: Could not fetch model of type 'GradleBuild' using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.8.3-bin.zip'.
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Initialization script 'C:\Workspaces\Java\K2\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle'
Could not compile initialization script 'C:\Workspaces\Java\K2\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle'.
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.gradle.groovy.scripts.ScriptCompilationException: Could not compile initialization script 'C:\Workspaces\Java\K2\.metadata\.plugins\org.eclipse.buildship.core\init.d\eclipsePlugin.gradle'.
at
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during semantic analysis: Unsupported class file major version 60
java.lang.IllegalArgumentException: Unsupported class file major version 60
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:196)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:177)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:163)
at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:284)
at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:81)
at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(ClassNodeResolver.java:251)
at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:189)
答案 0 :(得分:1)
您使用的 Gradle 6.x 似乎不支持在 Java 16 上运行。您可以降级到 Java 15 或更早版本或升级到 Gradle 7.x。
如果您降级 Java,您仍然可以使用 Gradle 的工具链支持在 Java 16 上构建和运行您的应用。
如果你升级到 Gradle 7.x,你还应该升级到 Spring Boot 2.5.x,它增加了对 Gradle 7 的支持。