Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task graph / .. task that depends on other settings - broken example #500

Open
kelemensanyi opened this issue Sep 28, 2017 · 3 comments
Open
Labels

Comments

@kelemensanyi
Copy link

In the Getting Started Guide this example is not working as described with sbt 1.0.2:
http://www.scala-sbt.org/1.x/docs/Task-Graph.html#Defining+a+task+that+depends+on+other+settings

$ cat build.sbt 
lazy val root = (project in file("."))
  .settings(
    name := "Hello",
    organization := "com.example",
    scalaVersion := "2.12.3",
    version := "0.1.0-SNAPSHOT",
    scalacOptions := List("-encoding", "utf8", "-Xfatal-warnings", "-deprecation", "-unchecked"),
    scalacOptions := {
      val old = scalacOptions.value
      scalaBinaryVersion.value match {
        case "2.12" => old
        case _      => old filterNot (Set("-Xfatal-warnings", "-deprecation").apply)
      }
    }
  )

$ sbt about
[info] Updated file /home/kelemen/temp/sbt-started/project/build.properties: set sbt.version to 1.0.2
[info] Loading project definition from /home/kelemen/temp/sbt-started/project
[info] Updating {file:/home/kelemen/temp/sbt-started/project/}sbt-started-build...
[info] Done updating.
[info] Loading settings from build.sbt ...
[info] Set current project to Hello (in build file:/home/kelemen/temp/sbt-started/)
[info] This is sbt 1.0.2
[info] The current project is {file:/home/kelemen/temp/sbt-started/}root 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.3
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.3

$ sbt
[info] Loading project definition from /home/kelemen/temp/sbt-started/project
[info] Loading settings from build.sbt ...
[info] Set current project to Hello (in build file:/home/kelemen/temp/sbt-started/)
[info] sbt server started at 127.0.0.1:5797
sbt:Hello> show scalacOptions
[info] * -encoding
[info] * utf8
[info] * -Xfatal-warnings
[info] * -deprecation
[info] * -unchecked
[success] Total time: 0 s, completed Sep 28, 2017 5:53:13 PM
sbt:Hello> ++2.11.8
[info] Setting Scala version to 2.11.8 on 0 projects.
[info] Excluded 1 projects, run ++ 2.11.8 -v for more details.
[info] Reapplying settings...
[info] Set current project to Hello (in build file:/home/kelemen/temp/sbt-started/)
sbt:Hello> show scalacOptions
[info] * -encoding
[info] * utf8
[info] * -Xfatal-warnings
[info] * -deprecation
[info] * -unchecked
[success] Total time: 0 s, completed Sep 28, 2017 5:53:30 PM

The problem is with the second execution of show scalacOptions, because according to the example it should only display -encoding, utf8, -unchecked and NOT -Xfatal-warnings and -deprecation.

@kelemensanyi
Copy link
Author

Adding crossScalaVersions := Seq(scalaVersion.value, "2.11.8"), seems to solve it:

$ cat build.sbt 
lazy val root = (project in file("."))
  .settings(
    name := "Hello",
    organization := "com.example",
    scalaVersion := "2.12.3",
    crossScalaVersions := Seq(scalaVersion.value, "2.11.8"),
    version := "0.1.0-SNAPSHOT",
    scalacOptions := List("-encoding", "utf8", "-Xfatal-warnings", "-deprecation", "-unchecked"),
    scalacOptions := {
      val old = scalacOptions.value
      scalaBinaryVersion.value match {
        case "2.12" => old
        case _      => old filterNot (Set("-Xfatal-warnings", "-deprecation").apply)
      }
    }
  )

$ sbt
[info] Updated file /home/kelemen/temp/sbt-started/project/build.properties: set sbt.version to 1.0.2
[info] Loading project definition from /home/kelemen/temp/sbt-started/project
[info] Updating {file:/home/kelemen/temp/sbt-started/project/}sbt-started-build...
[info] Done updating.
[info] Loading settings from build.sbt ...
[info] Set current project to Hello (in build file:/home/kelemen/temp/sbt-started/)
[info] sbt server started at 127.0.0.1:5797
sbt:Hello> show scalacOptions
[info] * -encoding
[info] * utf8
[info] * -Xfatal-warnings
[info] * -deprecation
[info] * -unchecked
[success] Total time: 0 s, completed Sep 28, 2017 6:03:10 PM
sbt:Hello> ++2.11.8
[info] Setting Scala version to 2.11.8 on 1 projects.
[info] Reapplying settings...
[info] Set current project to Hello (in build file:/home/kelemen/temp/sbt-started/)
sbt:Hello> show scalacOptions
[info] * -encoding
[info] * utf8
[info] * -unchecked
[success] Total time: 0 s, completed Sep 28, 2017 6:03:23 PM

@kelemensanyi
Copy link
Author

Might be related to sbt/sbt#2613

@dwijnand
Copy link
Member

Thank you for bringing this to our attention, @kelemensanyi!

@dwijnand dwijnand added the bug label Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants