Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ overrides Scala additional compiler options when synced from Gradle

I'm working on a Scala project in IntelliJ IDEA, and using Gradle for configuration and dependency management.

Every time I add some new dependency and sync it into IDEA, it rewrites Additional compiler options into -target:jvm-1.8, what results in a error when I try to make it with IDEA:

Error:scalac: 'jvm-1.8' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.8'

So I need to fix it manually.

Can I set target JVM version or compiler parameters (need also -feature option) in my build.gradle, so it would take them from there?

Thanks!

like image 388
Alexander Sheboltaev Avatar asked Aug 13 '14 12:08

Alexander Sheboltaev


1 Answers

You can add sourceCompatibility = '1.7' to your gradle build file and then refresh, the project will build normally. Note that this way you cannot have Java 8 source in your code, this is a temporary hack until Gradleware or JetBrains solve the issue.

You can also tamper with the IDEA project XML that is generated when running gradle idea. That would give you the option to include additional flags as well. You can check your current xml by opening the project .iml file and identifying what needs to be changed, then use the following code:

apply plugin: 'idea'

idea {
  module {
    iml {      
      withXml {
        def node = it.asNode()
        //modify xml
      }
    }
  }
}

Would not recommend it though, as you will have to stick with using gradle idea and won't be able to properly import straight from the IDEA, but currently there is no better way to have additional flags. Documentation - idea plugin and idea module

like image 73
Laurynas Tretjakovas Avatar answered Nov 12 '22 12:11

Laurynas Tretjakovas