Hi! Sorry, for a n00b question: I try to set up a ...
# spring
t
Hi! Sorry, for a n00b question: I try to set up a fresh created spring boot 3.0.5 application in a Java Devcontainer in VS Code. Depending on adding “kotlin.compiler.jvm.target”: “17" in settings.json I get either
Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option kotlin(INLINE_FROM_HIGHER_PLATFORM)
or the versions other way around.. Any hints to get it to work?
c
With Kotlin 1.8+ all that’s required is to set a Java toolchain:
Copy code
java {
    toolchain {     languageVersion.set(JavaLanguageVersion.of(17))
    }
}
w
I think this is not a gradle project?
t
Gradle or Maven doesn’t really matter - I tried maven as it seems to be better integrated with on-demand compiles in VS Code. Creating a new Gradle project and updating kotlin to 1.8.20 results in an additional error
Class 'kotlin.reflect.KClass' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The complete gradle setup is
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	id 'org.springframework.boot' version '3.0.5'
	id 'io.spring.dependency-management' version '1.1.0'
	id 'org.jetbrains.kotlin.jvm' version '1.8.20'
	id 'org.jetbrains.kotlin.plugin.spring' version '1.8.20'
}

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

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

java {
    toolchain {     languageVersion.set(JavaLanguageVersion.of(17))
    }
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	implementation 'org.jetbrains.kotlin:kotlin-reflect'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.withType(KotlinCompile) {
	kotlinOptions {
		freeCompilerArgs = ['-Xjsr305=strict']
		jvmTarget = '17'
	}
}

tasks.named('test') {
	useJUnitPlatform()
}
w
This might be an issue with the dependency management plugin. Try removing that and using the spring bom directly in gradle
1
152 Views