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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With