sbt / website

The source for scala-sbt.org
https://www.scala-sbt.org/
Apache License 2.0
77 stars 344 forks source link

Type mismatch in Task Graph examples #501

Open kelemensanyi opened 7 years ago

kelemensanyi commented 7 years ago

The Task Graph page http://www.scala-sbt.org/1.x/docs/Task-Graph.html contains three examples containing the expression ur.allConfigurations.take(3) which all seem broken:

$ cat build.sbt 
scalacOptions := {
  val ur = update.value  // update task happens-before scalacOptions
  val x = clean.value    // clean task happens-before scalacOptions
  // ---- scalacOptions begins here ----
  ur.allConfigurations.take(3)
}

$ 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.
/home/kelemen/temp/sbt-started/build.sbt:5: error: type mismatch;
 found   : scala.collection.immutable.Vector[sbt.librarymanagement.ConfigRef]
 required: Seq[String]
  ur.allConfigurations.take(3)
                           ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 
dwijnand commented 7 years ago

Thanks @kelemensanyi.

julian-20 commented 7 years ago

Hey there, I am new into sbt and I was also reading through the tutorial and hit the problem. I managed to edit the line to make it work, and it seems like that its working how its intented to work. I changed ur.allConfigurations.take(3) to ur.allConfigurations.take(3).foldLeft[Seq[String]](Nil)((a, b)=>{(b.name::Nil)++:a}) and its running without errors.

When I type show scalacOptions I am getting this result, which seems legit

sbt:Hello> show scalacOptions
[info] 123
[info] 456
[info] * test
[info] * runtime
[info] * compile
[success] Total time: 0 s, completed 02.12.2017, 23:59:43

I would like to have confirmation uppon that, because I can't really myself, as I am new into sbt.

EDIT: Ofcourse you would want to use foldRight not foldLeft like i did, to get the items in the correct order ur.allConfigurations.take(3).foldRight[Seq[String]](Nil)((a, b)=>{(a.name::Nil)++:b}) like this

sbt:Hello> show scalacOptions
[info] 123
[info] 456
[info] * compile
[info] * runtime
[info] * test
Irrizzit commented 6 years ago

ur.allConfigurations.map(_.toString) should be good enough :)

scalacOptions := {
  println("->>>>>>>>>>>>>>>>>>>>")
  var ur =  update.value
  clean.value
  println("-<<<<<<<<<<<<<<<<<<<<")
  ur.allConfigurations.map(_.toString)
},

gives then:

[IJ]sbt:work> show scalacOptions [info] Updating ... [info] Done updating. ->>>>>>>>>>>>>>>>>>>> -<<<<<<<<<<<<<<<<<<<< [info] compile [info] runtime [info] test [info] provided [info] optional [info] compile-internal [info] runtime-internal [info] test-internal [info] plugin [info] pom [info] * scala-tool [success] Total time: 1 s, completed Feb 25, 2018 10:42:55 PM [IJ]sbt:work>