Trouble importing Spring Boot Gradle project into Eclipse

Viewed 3051

I have a Sprint Boot project that I built on another system that I'm trying to import into a new one into Eclipse (4.20.0), and I'm having some issue. It's a Gradle Spring Boot. My build.gradle file is below. I have JKD 16.0.1 install on the machine -- Windows 10.

I've tried importing it with both the Gradle buildship and STS plugins. When I try the Buildship, it fails on the import preview with a big stack dump, with the top line:

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

When I try Gradle STS, when I hit the "Build Model" button, I tells me errors appeared and to check the log file. The interesting thing I find in there are these:

!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

I also tried building it from the terminal to get some clues. That gives me the "Unsupported class file major version 60" error.

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

This looks like a real mess. Where do I start solving this?

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()
}

Error from 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)
1 Answers

It looks like you are using Gradle 6.x which does not support running on Java 16. You could downgrade to Java 15 or earlier or upgrade to Gradle 7.x.

If you downgrade Java, you could still build and run your app on Java 16 by using Gradle’s toolchain support.

If you upgrade to Gradle 7.x, you should also upgrade to Spring Boot 2.5.x which added support for Gradle 7.

Related