Scala not builds on Java 10 - scala

while building through Intellij Idea, I got the following message:
Error:scalac: 'jvm-1.10' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.10'
later, after a Java upgrade
Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM:
1.8 Build, Execution, Deployment -> Complier -> Scala Complier -> Scala Compile Server -> JDK: 1.8
in build.gradle
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
Nothing helps!
upd:
this helps: in build.gradle
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
not needed:
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false

"Error:scalac: 'jvm-1.10' is not a valid choice for '-target' Error:scalac: bad option: '-target:jvm-1.10'"
In the JDK compatibility notes as mentioned below, it also indicates
that the Java 10 is not fully supporting Scala 2.12.6 JDK 9 & 10
compatibility notes
As you were saying you build this through IntelliJ IDEA, I suspect
you haven't configure your java version (Java 10) or scala version
(2.12.6) inside running configuration project settings.
And also please try out building/compile your application through
commandline in order to check whether you are getting the same error
with that (Otherwise this is just bad configuration in IDEA tht you
need to change)
JDK 9 & 10 compatibility notes (Mentioned in Scala Docs)
JDK 9 & 10 compatibility notes
As of Scala 2.12.6 and 2.11.12, JDK 9 & 10 support is incomplete. Notably, scalac will not enforce the restrictions of the Java Platform Module System, which means that code that typechecks may incur linkage errors at runtime.
JDK 9 & 10 support requires minimum sbt version 1.1.0, or 0.13.17 in the 0.13.x series.
For more information on JDK 9 & 10 compatibility, watch the “Support JDK 9” issue on GitHub.

The same issue can happen with mixed multi-module gradle projects that use java 11 and scala 2.12.10.
In that case, it may help to reconfigure IntelliJ (2019.2) via
Settings > Build, Execution, Deployment > Scala Compiler
by removing the targets defined in Additional compiler options for the affected scala modules.

I stumbled over this issue when having the same problem with Java 11. The reconfiguration comment of Roland Ewald solved the problem. It is important to mention, that this reconfiguration has to be made for all modules of the project (at least for me this was necessary) as well as that IntelliJ sometimes hides parts of the Additional compiler options, so be sure to click on expand even if they seem empty or correct.

Related

How to fix the Error: "org.jetbrains.jps.incremental.scala.remote.ServerException java.lang.StackOverflowError"

I'm trying to run the main class in the scala-sbt project. Running the class is resulting in stackoverflow Error, StackTrace pasted below.
I am sure this is not a code Issue because for the same project I was able to run sbt package by setting the memory in sbt conf file as described here: https://stackoverflow.com/q/55874883.
I tried to set the params in Intellij> Settings> Scala Compile Server, but it didn't help to overcome Error.
JDK: Profile Default
Jvm maximum heap size, MB: 2024
JVM options: -server -Xmx2G -Xss20m -XX:MaxPermSize=1000m -XX:ReservedCodeCacheSize=1000m
IntelliJ:
IntelliJ IDEA 2019.1 (Community Edition)
Build #IC-191.6183.87, built on March 27, 2019
JRE: 1.8.0_202-release-1483-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Sbt Version: 1.2.8
Scala Version: 2.11.8
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
java.lang.StackOverflowError
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:273)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.noTailTransform(TailCalls.scala:214)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:403)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.noTailTransform(TailCalls.scala:214)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:403)
at scala.tools.nsc.transform.TailCalls$TailCallElimination.transform(TailCalls.scala:209)
redacted...
I've had the same issue with Intellij IDEA Ultimate 2020.1.1.
None of above options worked for me. But with a hint of the above answer, I found there was also different setting for the Scala compiler, after changing it the error stopped.
I increased the size of stack trace of the Scala compiler server: Preferences -> Compiler -> Scala Compiler -> Scala Compiler Server. Then, change the JVM options accordingly (In my case, -server -Xss1024m).
I've had the same issue with Intellij IDEA Community Edition 2019.3.4.
In the end, what worked for me was this solution. Basically, go to Settings -> Build, Execution, Deployment -> Compiler
Then, on "User-local build process VM options" set the stack size to a greater value with -Xss
In my case, I finally managed to run the tests setting it to -Xss2048m
I hope this helps.
Go to Configure → Edit Custom VM Options and add your changes there
If you're able to do sbt package (so you have sufficient heap size and -Xss configured for sbt) but running class still throws java.lang.StackOverflowError try going to
Settings -> Build, Execution, Deployment -> sbt
and tick
sbt shell -> use for: project reload and builds
try those options

Error:scalac: 'jvm-1.9' is not a valid choice for '-target'

Created a new clean Scala project using Gradle.
This is the only dependency:
compile "org.scala-lang:scala-library:2.12.4"
When building on the command line ./gradlew build works perfectly fine. However, when using IntelliJ it gives me this warning:
Error:scalac: 'jvm-1.9' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.9'
I have both the JDK with java 8 and 9 installed, but I'm currently using JDK 1.8. But I'm not sure if that's related.
In Scala 2.12, the Scala compiler always compiles to Java 8 compatible bytecode.
You can find more info below:
Compiling and testing Scala 2.12
Scala-lang: JAVA 8 BYTECODE FOR LAMBDAS
Add the following lines to your build.gradle:
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
I had the same problem and my issue was that gradle JDK was set to 9. I changed the JDK to 8 (Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM) and it worked

Troubles launching Kestrel

I am try to play with Kestrel 2.4.1 (http://robey.github.io/kestrel/). Unfortunately, it does not launch. I get the following exception when I run the devel.sh script. IOther scripts produce similar exception.
Starting kestrel in development mode...
May 17, 2014 2:26:06 PM java.util.logging.LogManager$RootLogger log
FATAL: Error in config file: %s
java.lang.UnsupportedOperationException: Position.line
at scala.tools.nsc.util.Position$class.line(Position.scala:173)
at scala.tools.nsc.util.NoPosition$.line(Position.scala:196)
at com.twitter.util.Eval$StringCompiler$$anon$1.display(Eval.scala:444)
at scala.tools.nsc.reporters.AbstractReporter.info0(AbstractReporter.scala:45)
Any help would be appreciated. I am using Java 8.
Scala support for Java 8 is experimental even in 2.11.0, and the github version has the last version of Scala being used as 2.9.2
From: Kestrel Build File
scalaVersion := "2.9.2",
From: SCALA 2.11.0 IS NOW AVAILABLE!
The Scala 2.11.x series targets Java 6, with (evolving) experimental support for Java 8. In 2.11.0, Java 8 support is mostly limited to reading Java 8 bytecode and parsing Java 8 source. Stay tuned for more complete (experimental) Java 8 support.
I would not expect this to work on Java 8 without having to fix compile issues for 2.10 and 2.11 and then Scala would need better support for Java 8.
Actually it's Logger can not init correctly.
Make sure queuePath and filename of development.scala are available.

UnsupportedClassVersionError deploying EJB "HelloWord" in Glasshfish 3

I try to deploy a simple "Hello Word" in my local server GlasshFish 3, but at the deploy the console print this message
[#|2013-01-15T15:00:02.458+0100|SEVERE|glassfish3.1.2|
javax.enterprise.system.tools.admin.org.Exception while deploying the app
[HelloWorldEJB] :UnsupportedClassVersionError: Class ejb_other.PlaceAuctionItemBean
as unsupported major or minor version numbers, which are greater than those found
in the Java Runtime Environment version 1.6.0_27|#]
My JAVA_HOME has java version 1.6.0_27 (it refers to _C:\Program Files\Java\jdk1.6.0_27_), my Eclipse (indigo) project refers to java 1.6.0_27.
I think (i don't know how to verify) that GlasshFish refers to JAVA_HOME.
In my PC (Windows 7) I found 2 directory having java.exe:
C:\Windows\SysWOW64>java -version -->>java version "1.6.0_29"
C:\Windows\System32>java -version -->>java version "1.6.0_27"
I found more discussions about this exception (f.e. this or this ), but I need of something more specific for Eclipse/Glasshfish, because I can't to solve. I see that the JVM is the same for compilation and execution.
Post Scriptim
I add the screenshot about the places where I declare JVM: it's always 1.6.
one:
two:
three:
Where can I see that I compile with java 7 or it runs with another JVM?
ejb_other.PlaceAuctionItemBean was obviously compiled for Java 7 which won't work if you run it in a Java 6 JVM.
Found solution
There's another place where setting the compiler's options:
how do I get eclipse to use a different compiler version for Java?

Scala plugin for IntelliJ IDEA 10 not detecting simple errors?

I know I must be missing something, but can't figure out what. When I create a scala project, following the scala-plugin instructions, not a single syntax error is detected. For example:
object MyApp {
val aNumber: Int = "hello"
}
does not detect any error. If I right-click and ask it to compile, then I get the expected type mismatch error from the scala compiler. This is just a silly example, no syntax errors are being flagged. For regular Java projects it works fine, so it must be scala specific.
I have a clean install of IDEA 10 CE on a OSX 10.6 and Scala 2.8.1 final. I have set up the jdk in the project settings as well as the scala home when creating the project. I have the latest version of the plugin (12/2010).
Any hint on what I'm missing?
You have to enable error highlighting. Turn on Settings/Code Style/Scala/Other settings/Enable experimental error highlighting
Works here too (IntelliJ 10.0.1, Scala 2.8.1, OpenJDK, Ubuntu 10.10 64bit).
If you want more type checking you can also tick "Enable experimental error highlighting (possibly shows many wrong red code)" in the Settings, but this shouldn't make a difference in your case, although it works perfectly in my case for a large code base.
In project structure > modules > [your project name] > dependencies tab, do you have scala-compiler-[some version] listed?
See the Exploring the Project Structure here
intelliJ IDEA 10.0.1 + scala 2.8.1 on Ubuntu 10.10 64bit.
It shows a type mismatch error
For 2019.1 CE on Mac OS:
Preferences | Build, Execution, Deployment | Compiler | Scala Compiler
Checked the option:
Features->Experimental Features