question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use Scala 2.11 -Ywarn-unused-import because it trips up the initialCommands

See original GitHub issue

I’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:closed
  • Created 9 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
som-snyttcommented, Jan 19, 2015

It sure is nice having config in Scala, because if it compiles, it just works.

2reactions
dwijnandcommented, Jun 21, 2016

Warning no-ops aside, I think scalacOptions in console should do what it says on the tin.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found