How do I get IntelliJ to display the Scala compilation deprecation warnings - scala

In IntelliJ (version: 2016.3.1, Scala Plugin version: 2016.3.5), I have a Scala 2.12 (which implies Java 1.8 being required) project where I am selecting "Build/Rebuild Project". I am receiving the following output in the "Messages" windows:
Warning:scalac: there were four deprecation warnings (since 2.12.0); re-run with -deprecation for details
What steps must I take to configure my project such that I can actually see the content of the 4 warnings?
I found another question for IntelliJ 14 which showed how to turn on deprecation warnings, but didn't indicate how to surface the actual content of the deprecation warnings themselves. Any guidance on this would be greatly appreciated.

Add the following to your sbt build file:
scalacOptions += "-deprecation"

As of the latest Intellij version at this time, you can also open Settings -> Build, Execution, Deployment -> Compiler -> Scala Compiler, and in Additional compiler options:, append -deprecation.

Related

Scala not builds on Java 10

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.

Scala compiler other than 2.12 not working in Eclipse

I just set up a Scala project in Eclipse (Oxygen 4.7.3a, on Ubuntu 18.04) with the Scala-IDE plugin (4.7.0.v-2_12-201709291352-71a28d0) with a simple HelloWorld object. If I set "Properties -> Scala Compiler" to 2.12 everything works as expected: the project compiles and runs. But if I choose any other version (for instance, "Latest 2.10 bundle (dynamic)" I get prompted to do a full rebuild (as expected) but when I go to "Project -> Build" nothing happens. If I have errors in my code, the editor underlines them, but they won't show in "Problems". If I try to run it I get a class not found error.
I get the feeling that it is not actually compiling. Any ideas on what I need to configure differently?
I finally solved it by removing openjdk-11 and installing openjdk-8. After doing that and reinstalling Eclipse and Scala-IDE everything works fine.
It would have been helpful having some feedback from Eclipse regarding what was not working. I figured it out because I tried to build with SBT and the error lead to this SO question: Failed to initialize compiler: object java.lang.Object in compiler mirror not found
I tried the update-alternatives option (also changing the Java path in eclipse.ini) but then I got the "object java.lang.Object in compiler mirror not found" error in Eclipse problems. Since I didn't need openjdk-11 anyway I simply switched to openjdk-8.

How to make SBT not reporting compilation warnings for generated code?

I generate code with the scalaxb-sbt plugin that, when compiled, generates a good number of warning messages. Is there any way to hide compilation warnings for generated code or by package?
The silencer compiler plugin allows to suppress compiler warnings. It supports filtering out files by path. This will filter out all generated files from warnings:
scalacOptions += "-P:silencer:pathFilters=src_managed"
For Scala 2.12.13+ or 2.13.2+
Recent versions of the Scala compiler integrate the silencer plugin, see configurable warnings.
So now you don't need any plugin, just add the following line to build.sbt:
ThisBuild / scalacOptions += "-Wconf:src=src_managed/.*:silent"
Using this option will suppress warnings for generated code that lives under a directory called src_managed anywhere in your source tree.
This solved my problem with code generated by zio-grpc, where the compiler emitted warnings like parameter value evidence$3 in method live is never used (adding this info only for better searchability).
In your sbt console you could try the following:
set logLevel in compile := Level.Error or eventually set logLevel in sourceGenerators := Level.Error
and experiment with different settings. Once you are happy you could apply this setting in your build.sbt.
More detailed information can be found in the sbt documentation: http://www.scala-sbt.org/release/docs/Howto/logging.html
I found that I needed to do set logLevel in Compile := Level.Error in my sbt console session in order for this to work. This is with a capital C in Compile. This is with sbt version 0.13.11. This is also to turn all warnings off, though.
Put the code in a subproject, and set scalacOptions differently in that project? Whether this will work depends on whether the support even exists in scalac for suppressing the particular kind of warning you are getting. See for example https://issues.scala-lang.org/browse/SI-1781 . What kind of warnings are you needing to suppress exactly? Certain warnings like unchecked warnings can be suppressed with e.g. #unchecked without having to do the subproject thing.

Scala warnings, IntelliJ and compiler flags

I'm currently giving the IntelliJ Scala plugin a spin and one thing is bugging me a wee-bit. I get 3 warnings when compiling.
Warning: scala: Recompiling 4 files
Warning: scala:
Warning: scala: there were 1 deprecation warnings; re-run with -deprecation for details
Why does it give me warnings that files are being recompiled? Can that be turned off? And finally, what's with the empty warning? :D
In IntelliJ 14:
Bring up preferences Intellij IDEA > Preferences or cmd + ,
Look up Scala Compiler. Alternatively, it's under Build, Execution, Deployment > Compiler > Scala Compiler
Check the option for Deprecation warnings
Rebuild your project!
I would like to add few words about warnings and errors reported by IntelliJ IDEa.
JetBrains uses it's own scala analyzer to identify and report errors. Sometimes it reports fake errors or warnings. I think this is because scala is much more complicated language from compilers point of view then much of other languages. Even if all official scala specification was implemented there are some cases which have been omited (read: There always are some bugs). If you find something reported as error/warning by your IntelliJ IDEa which is ok for scalac compiler you can always try to report it as a bug (IntelliJ IDEa supports reporting bugs). Guys from JetBrains will fix it.
More over some scala libraries use macros that are compiler extentions which adds some extra compiler behaviour. If IDE did know their specification it wouldn't identify these non standard codes as errors. It's better to be aware of that. I think the same touches Eclipse scala IDE.
Summarizing all above:
Do not trust all warnings and errors that IntelliJ or other IDE is telling you unless it compiles well using scalac.
JVM parameters isn't compiler parameters -- first are used to actually run your code, later used to just compile it to bytecode. You need to open project settings and adjust options there:

Scala Compiler doesn't compile in ScalaIDE

I'm trying to develop on the Scala compiler project with the help of ScalaIDE. I followed this guide to set up the development environment. When I now try to build the mentioned projects, the reflect project won't get built. Instead, I get the following error via the console output:
uncaught exception during compilation: scala.reflect.internal.MissingRequirementError reflect Unknown Scala Problem
Having tried the provided ANT script of the project via the console, everything seems to work fine.
Does anyone know if I'm missing a hidden compiler flag, dependency or something like this?
Thanks!
With the IDE for Scala 2.10 you can only build the 2.10.x branch of the Scala compiler. If you want to work on master, you need to install a 2.11-based version of the IDE. We don't publicise IDE for 2.11 nightlies yet, but they are available at:
http://download.scala-ide.org/nightly/scala-ide-master-2.11.0-SNAPSHOT/