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

Can't set jvm-target option on Kotlin Compiler #84

Closed
jmmk opened this issue Jan 5, 2018 · 6 comments
Closed

Can't set jvm-target option on Kotlin Compiler #84

jmmk opened this issue Jan 5, 2018 · 6 comments

Comments

@jmmk
Copy link

jmmk commented Jan 5, 2018

[kscript] [ERROR] compilation of './MyScript.kt' failed
MyScript.kt:53:68: 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' option
    ...

As far as I can tell, there's currently no way to override the JVM target. Am I missing a configuration option? If not, could it be added (ability to set -jvm-target specifically or maybe a hook to kotlinc_opts)?

@holgerbrandl
Copy link
Collaborator

Could you attach an example?

@jmmk
Copy link
Author

jmmk commented Jan 6, 2018

MyScript.kt:

#!/usr/bin/env kscript

@file:DependsOn("org.jetbrains.kotlin:kotlin-reflect:1.1.60")
@file:DependsOn("com.github.kittinunf.fuel:fuel-jackson:1.12.0")

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.jackson.responseObject


val mapper: ObjectMapper = jacksonObjectMapper()
    .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

data class User(val id: String, val name: String)
fun main(args: Array<String>) {
    val (_, _, result) = Fuel.get("https://jsonplaceholder.typicode.com/users").responseObject<User>()
}

running ./MyScript.kt produces:

[kscript] [ERROR] compilation of './MyScript.kt' failed
MyScript.kt:18:81: 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' option
    val (_, _, result) = Fuel.get("https://jsonplaceholder.typicode.com/users").responseObject<User>()
                                                                                ^

@holgerbrandl
Copy link
Collaborator

Same for me.

The kotlinc default is 1.6 for a reason (I guess/hope), so simply using 1.8 as kscript default feels a bit inconsistent. However, the main motivation for using 1.6 is most likely android compatibility, which does not matter with respect to kscript, so maybe using 1.8 is not so wrong after all.

At the moment compiler flags used by kscript can't be adjusted. We could add another directive (e.g. named @CompilerOpts) to allow the user to adjust compiler behavior if needed.

What do you think?

@jmmk
Copy link
Author

jmmk commented Jan 8, 2018

@holgerbrandl I think that makes sense. There's @KotlinOpts to configure runtime flags, so something like @CompilerOpts or @KotlincOpts would be nice to configure compiler flags

@jasoet
Copy link

jasoet commented Feb 1, 2018

+1

1 similar comment
@sail-y
Copy link

sail-y commented Feb 7, 2018

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants