I'm building scala project using gradle 4.5, scala 2.11.11/2.12.4 with JDK 1.8.0_162 and it was working fine until I upgrade to scala 2.11.12. With 2.11.12 I keep getting compile error
Static methods in interface require -target:jvm-1.8
I've been trying to search in google and add couple of stuffs like
ScalaCompileOptions.metaClass.useAnt = false
Or
targetCompatibility="1.8"
but none of them fix the issue.
Java interface static method helps us in providing security by not allowing implementation classes to override them. We can't define interface static method for Object class methods, we will get compiler error as “This static method cannot hide the instance method from Object”.
Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. A static method is a method that is associated with the class in which it is defined rather than with any object.
Static methods can be accessed without having to create a new object. A static method can only use and call other static methods or static data members. It is usually used to operate on input arguments (which can always accept), perform calculation and return value.
Features of static method:Every instance of a class has access to the method. Static methods have access to class variables (static variables) without using the class's object (instance). Only static data may be accessed by a static method. It is unable to access data that is not static (instance variables).
An addition to @Wins answer for those using maven with scala-maven-plugin
. You need to add the following line to plugin configuration:
<addScalacArgs>-target:jvm-1.8</addScalacArgs>
Ok, after struggling with this problem for a few weeks and decided to post on SO, I try to fiddle further more with gradle, I finally managed to fix this problem.
Turns out that I have to add these two lines to gradle
project.tasks.compileScala.scalaCompileOptions.additionalParameters = ["-target:jvm-1.8"] project.tasks.compileTestScala.scalaCompileOptions.additionalParameters = ["-target:jvm-1.8"]
This is fixing the issue and it doesn't come back.
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