Why sbt.Extracted remove the previously defined TaskKey while append method?

72 views
Skip to first unread message

Barys Ilyushonak

unread,
Mar 25, 2015, 2:13:06 PM3/25/15
to sbt...@googlegroups.com

Hi there,

There is a suitable method in the sbt.Exctracted to add the TaskKey to the current state. Assume I have inState: State:

val key1 = TaskKey[String]("key1")
Project.extract(inState).append(Seq(key1 := "key1 value"), inState)

I have faced with the strange behavior when I do it twice. I got the exception in the following example:

val key1 = TaskKey[String]("key1")
val key2 = TaskKey[String]("key2")
val st1: State = Project.extract(inState).append(Seq(key1 := "key1 value"), inState)
val st2: State = Project.extract(st1).append(Seq(key2 := "key2 value"), st1)
Project.extract(st2).runTask(key1, st2)

leads to:

java.lang.RuntimeException: */*:key1 is undefined.


The question is - why does it work like this? Is it possible to add several TaskKeys while executing the particular task by several calls to sbt.Extracted.append?

The example sbt project is sbt.Extracted append-example, to reproduce the issue just run sbt fooCmd


I'm not sure should I create an issue about that or that behavior is correct by design. I have created sso question for that: http://stackoverflow.com/questions/29251711/why-sbt-extracted-remove-the-previously-defined-taskkey-while-append-method 

Please, advice.

Barys Ilyushonak

unread,
Mar 26, 2015, 8:47:01 AM3/26/15
to sbt...@googlegroups.com
I forgot to mention the sbt version: I have tested that with

sbt.version=0.13.8
and
sbt.version=0.13.6

and the scalaVersion 2.11.5

Enter code here...



Josh Suereth

unread,
Mar 27, 2015, 9:47:36 AM3/27/15
to sbt...@googlegroups.com
The `append` function is pretty dirty/low-level.  This is probably a bug in its implementation (or the lack of documentation), but it blows away any other appended setting when used.

What you want to do, (I think) is append into the current "Session" so things will stick around and the user can remove what you've done via "sesison clear" command.


Additonally, the settings you're passing are in "raw" or "fully qualified" form.  If you'd for the setting you  write to work exactly the same as it would from a build.sbt file, you need to transform it first, so the Scopes match the current project, etc.

We provide a utility in sbt-server that makes it a bit easier to append settings into the current session:


Ideally the "append" method would work like the one there, but currently it does not.   We've started to migrate our own code away form "append" given the bugs we found in its implementation.  Looks like we should just formally deprecate it, and provide a new implementation (with different semantics) for you to use.  For now, check out settingutil from sbt-server.

--
You received this message because you are subscribed to the Google Groups "sbt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sbt-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sbt-dev/879dd5cc-9114-4755-8196-c78f04ec95c9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Barys Ilyushonak

unread,
Mar 30, 2015, 7:02:29 AM3/30/15
to sbt...@googlegroups.com
Dear Jost,

thank you very much for the answer. That works like a charm. I my case the scoping the Keys in the session is even more accurate way to go.

PS. Will you update stackoverflow question or can I do it?

среда, 25 марта 2015 г., 19:13:06 UTC+1 пользователь Barys Ilyushonak написал:

Josh Suereth

unread,
Mar 30, 2015, 7:33:47 AM3/30/15
to sbt...@googlegroups.com
You may do it if you'd like the upvotes :)

--
You received this message because you are subscribed to the Google Groups "sbt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sbt-dev+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages