fwcd/kotlin-language-server

Please specify proper '-jvm-target' optionkotlin(INLINE_FROM_HIGHER_PLATFORM)

laibulle opened this issue ยท 18 comments

Trying to use the plugin with java 11 on OSX.

openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

It is a simple project generate via springr.

I get the following error

Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' optionkotlin(INLINE_FROM_HIGHER_PLATFORM)

screenshot 2018-12-28 at 03 05 39

You can reproduce using this repo https://github.com/laibulle/spring-kotlin-sample. The code run via

gradle bootRun

Best regards

fwcd commented

This might be related to #20. Java 9+ support is still experimental.

I switch back to Java 8

java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)

and still have the same message.

kenpb commented

Same problem here, setting the kotlin.compiler.jvmtarget in maven or the jvmTarget in gradle have no effect whatsoever.

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
info: kotlinc-jvm 1.3.30-eap-125 (JRE 1.8.0_131-b11)

Any more info we can provide to help out?,
Cheers!

I'm having this same issue. Could you add a VSCode setting to change the version of the jvmTarget attribute? My build.gradle.kts file is set to use the correct jvmTarget, but the Kotlin language server doesn't respect this value.

Here's the relevant portion of my Gradle configuration:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

tasks.withType<KotlinCompile> {
    kotlinOptions.suppressWarnings = true
    kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}

The specific error I'm getting is a little different than others, but the root cause is similar.

Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'kotlin(INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR)

Screen Shot 2019-07-03 at 11 37 39 AM

I've also bumped into this problem. Is there some kind of "brute force" approach to solve this problem? For example, force KLS to always use 1.8. This would be sufficient for my purposes for now since I am using the same Java version on all my projects.

I have same problem too.
And I created a patch that forcely set jvm-target to 1.8. It works well :)

diff --git a/server/src/main/kotlin/org/javacs/kt/Compiler.kt b/server/src/main/kotlin/org/javacs/kt/Compiler.kt
index 0f223df..e310b90 100644
--- a/server/src/main/kotlin/org/javacs/kt/Compiler.kt
+++ b/server/src/main/kotlin/org/javacs/kt/Compiler.kt
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
 import org.jetbrains.kotlin.config.CommonConfigurationKeys
 import org.jetbrains.kotlin.config.CompilerConfiguration
 import org.jetbrains.kotlin.config.JVMConfigurationKeys
+import org.jetbrains.kotlin.config.JvmTarget
 import org.jetbrains.kotlin.container.ComponentProvider
 import org.jetbrains.kotlin.container.get
 import org.jetbrains.kotlin.idea.KotlinLanguage
@@ -49,6 +50,7 @@ class Compiler(classPath: Set<Path>) {
     private val config = CompilerConfiguration().apply {
         put(CommonConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
         put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, LoggingMessageCollector)
+        put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8)
         addJvmClasspathRoots(classPath.map { it.toFile() })
     }
     val environment: KotlinCoreEnvironment

Genius! thanks @kuro46, applying the patch locally as we speak :-)

Applied, works as advertised! :-) Thanks very much!

fwcd commented

@kuro46 Thank you very much, I will add this as a configuration option to the language server!

fwcd commented

Fixed by #128.

Wow that was fast! :-) bit of a newbie question, where do I place the new config option kotlin.compiler.jvm.target? TIA

fwcd commented

@mcraveiro LSP has a workspace/didChangeConfiguration method for this, not sure how this is implemented on the Emacs side though.

Aha, excellent - I'll dig through the lisp. Cheers

fwcd commented

To add to this, this is a sample configuration taken from my current setup:

{"kotlin":{"languageServer":{"enabled":true},"compiler":{"jvm":{"target":"1.8"}},"linting":{"debounceTime":250},"completion":{"snippets":{"enabled":true}},"debounceTime":250,"snippetsEnabled":true}}

This object is passed as part of the DidChangeConfigurationParams:

interface DidChangeConfigurationParams {
	/**
	 * The actual changed settings
	 */
	settings: any;
}

Edit: Not all keys have to be present, those that aren't are simply left at their current/default values, so if you just want to set the JVM version, you could do something like this:

{"kotlin":{"compiler":{"jvm":{"target":"1.8"}}}}

How can I change the target in a maven project in vscode? I'm getting the same error in a spring-boot project.

For anyone that is struggling with this in Neovim, you can set the lsp config as follows and it should fix the problem.

lua require'lspconfig'.kotlin_language_server.setup{ settings = { kotlin = { compiler = { jvm = { target = "1.8" } } } } }

vim + vim-lsp fixed with adding workspace config:

let g:lsp_settings = {
\  'kotlin-language-server': {
\    'workspace_config': {
\      'kotlin': {'compiler': {'jvm': {'target': '17'}}}
\    }
\  }
\}

I'm getting same issue.
I'm using a fresh lazyvim kotlin language server. You can see default configuration here.

It's not clear to where should I override jvm-target setting.

I guess I should need to create an additional config file...

Any ideas?