Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
laibulle opened this issue Dec 28, 2018 · 16 comments
Closed
Labels
bug Something isn't working

Comments

@laibulle
Copy link

laibulle commented Dec 28, 2018

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

@laibulle laibulle changed the title 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) Please specify proper '-jvm-target' optionkotlin(INLINE_FROM_HIGHER_PLATFORM) Dec 28, 2018
@fwcd
Copy link
Owner

fwcd commented Dec 28, 2018

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

@fwcd fwcd added the bug Something isn't working label Dec 28, 2018
@laibulle
Copy link
Author

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
Copy link

kenpb commented May 28, 2019

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!

@pcgeek86
Copy link

pcgeek86 commented Jul 3, 2019

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

@mcraveiro
Copy link

mcraveiro commented Jul 17, 2019

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.

@kuro46
Copy link
Contributor

kuro46 commented Jul 18, 2019

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

@mcraveiro
Copy link

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

@mcraveiro
Copy link

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

@fwcd
Copy link
Owner

fwcd commented Jul 18, 2019

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

@fwcd
Copy link
Owner

fwcd commented Jul 18, 2019

Fixed by #128.

@fwcd fwcd closed this as completed Jul 18, 2019
@mcraveiro
Copy link

mcraveiro commented Jul 18, 2019

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

@fwcd
Copy link
Owner

fwcd commented Jul 18, 2019

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

@mcraveiro
Copy link

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

@fwcd
Copy link
Owner

fwcd commented Jul 18, 2019

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"}}}}

@ahmadmu
Copy link

ahmadmu commented Nov 26, 2019

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

@justinhj
Copy link

justinhj commented May 14, 2021

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" } } } } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants