Can't use Scala 2.11 -Ywarn-unused-import because it trips up the initialCommands
See original GitHub issueI’m trying to use the Scala 2.11 -Ywarn-unused-import
option while compiling, but not in the console, where it effectively disables the ability to use most imports, especially in initialCommands
.
Here’s a sample ./project/Build.scala
file:
import sbt._
import sbt.Keys._
object MyBuild extends Build {
import Resolvers._
import BuildSettings._
val commonScalacOptions = Vector("-deprecation", "-unchecked", "-feature",
"-encoding", "utf8",
"-Yno-adapted-args", "-Ywarn-dead-code",
"-Ywarn-numeric-widen", "-Ywarn-value-discard")
val compileScalacOptions = commonScalacOptions ++ Vector("-Ywarn-infer-any", "-Ywarn-unused-import")
val scalaTest = "org.scalatest" %% "scalatest" % "2.2.1" % "test"
lazy val myProject = Project(
id = "SampleProject",
base = file("."),
settings = buildSettings ++ Seq(
version := "0.1.0",
scalaVersion := "2.11.4",
scalacOptions in Compile := compileScalacOptions,
scalacOptions in console := commonScalacOptions,
libraryDependencies ++= Seq(scalaTest)))
}
Here’s a sample ./build.sbt
:
initialCommands += """
import org.example.foo._
"""
Once I start sbt, I see the following:
> show *:console::scalacOptions
[info] Vector(-deprecation, -unchecked, -feature, -encoding, utf8, -Yno-adapted-args, -Ywarn-dead-code, -Ywarn-numeric-widen, -Ywarn-value-discard)
[success] Total time: 0 s, completed Jan 18, 2015 9:12:22 AM
> show compile:scalacOptions
[info] Vector(-deprecation, -unchecked, -feature, -encoding, utf8, -Yno-adapted-args, -Ywarn-dead-code, -Ywarn-numeric-widen, -Ywarn-value-discard, -Ywarn-infer-any, -Ywarn-unused-import)
But when I start the console, I get this:
> console
[info] Starting scala interpreter...
[info]
<console>:12: warning: Unused import
import org.example.foo._
^
import org.example.foo._
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0).
...
It appears that the full set of compile options are being used. Using :power
and :settings
confirms this.
On the mailing list, someone suggested adding -Ywarn-unused-import:false
to the scalacOptions in console
. However, this appears to have no benefit.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
sbt Reference Manual — Configure and use Scala
Set the Scala version used for building the project · Disable the automatic dependency on the Scala library · Temporarily switch to a...
Read more >how to compile continuations in scala 2.11 using sbt
I'm trying to compile a class using continuations in scala 2.11.2 and I can't get it to compile with sbt. The program compiles...
Read more >sbt Reference Manual - Manualzz
Supports testing with ScalaCheck, specs, and ScalaTest. JUnit is supported by a plugin. • Starts the Scala REPL with project classes and dependencies...
Read more >Scala 2.11.0 - The Scala Programming Language
x command. For example to install Scala 2.12 simply use sudo port install scala2.12; Use Scastie to run single-file Scala programs in your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It sure is nice having config in Scala, because if it compiles, it just works.
Warning no-ops aside, I think
scalacOptions in console
should do what it says on the tin.