9

I'm trying to get the Kotlin compiler to generate Java 1.8 bytecode instead of 1.6 bytecode. Both the official docs and this StackOverflow question say you need to use code like this:

compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

However, when I add this to my Gradle configuration, IntelliJ tells me that the symbol kotlinOptions cannot be resolved. Why is this? I'm using Kotlin v1.2.0, and it can compile code just fine, but it can't set this option.

3
  • what gradle version are you using? Does it work from the command line?
    – s1m0nw1
    Nov 30, 2017 at 8:46
  • Using Gradle 4.0. The project does indeed compile with the undefined kotlinOptions still present, but I don't think it's using JVM 1.8 bytecode.
    – Matt Y
    Nov 30, 2017 at 8:54
  • 2
    If you merely mean the warning when you edit/view build.gradle in IntelliJ, that's just a shortcoming of the way the DSL was defined in Groovy, so IntelliJ doesn't know about additional properties. If the property truly wasn't available, you'd get an error when you ran Gradle. Try changing kotlinOptions to kotlinO and see if Gradle still executes. It should now complain that it can't find method kotlinO.
    – Mikezx6r
    Nov 30, 2017 at 15:38

1 Answer 1

4

As @Mikezx6r explained, the option is there otherwise it wouldn't compile. It's just that IntelliJ does not see this. Note that the 'Cannot resolve symbol' inspection does not generate any error, warning or even typo, it only greys out the option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.