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
Document scope delegation in detail #357
Conversation
Inside of `foo`'s setting body the dependency a scoped key `(bar in Test)` is declared. | ||
However, as you see, `bar in Test` is undefined in `projA`. | ||
sbt is able to still resolve `(bar in Test)` to another scoped key, | ||
and initialize `foo` as `2`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it sounds obvious, but it would be a good idea to explain that this is because (if I understand correctly) the Test
scope extend
s the Compile
scope. It might also be worth explaining what it means for a scope to extend another scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just came here to write that
organization := "com.example", | ||
scalaVersion := "2.12.2", | ||
version := scalaVersion.value + "_0.1.0" | ||
)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to suggest that inThisBuild works/makes sense only in a settings()
call, while (IIRC) it works anywhere
#### Delegation in detail (.value lookup) | ||
|
||
Now that we've covered all the details of scoping, we can explain the `.value` | ||
lookup in detail. It's ok to skip this section at in the beginning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove at
lazy val foo = settingKey[Int]("") | ||
lazy val bar = settingKey[Int]("") | ||
|
||
lazy val projA = (project in file("a")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this in
method the same as the one below?
Very nice write-up! I knew most of this, but not as clearly as I do now. It also made be realize I had misunderstood the difference between |
@sjrd Having a good reference to link to people to explain the difference between Basically sbt doesn't just have multi-project support, it also has multi-build support. It's not a widely used feature. For example if you add a dependency on another project using As a rule of thumb I would suggest to always use
|
Huh! Wow. TIL. Looks like this multi-build feature could be a huge can of worms. I kind of always assumed that |
Yeah, I migrated away from my Have a look at this little session playing with how
|
How about a variant of |
Perhaps I can do a rewrite for this. I could detect if people use the project refs for external project, and if not rewrite |
What do you mean by shadowed "resolutions"? Do you mean that you would like to see all the scopes that were eligible but were not selected because of the higher precedence of one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This writeup looks nice @eed3si9n. Thanks for your time on it. I have done a suggestion to improve a tricky part of the text.
are listed first, then falls back to `Global` (`*`) configuration. | ||
- Finally, Task axis scoping lists the given task value `console::` and the one without. | ||
|
||
Note that scope delegation feels similar to class inheritance in an object-oriented language, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest three things:
- Make this a top-level section.
- Avoid the term "dynamic dispatch" and describe what it really means. The example given is great, but it's difficult to parse for people because it involves understanding what dynamic dispatch. I would assume lots of people don't know what it is.
- Write a sbt example that shows this behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forget about the sbt example. I missed that there's already one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted your suggestion 1. I might work on 2 later.
Scope delegation (`.value` lookup) is one of more trickier aspect of build.sbt DSL. Based on the material covered in Scopes page, this adds a new page called Scope Delegation which breaks down delegation into rules and exercises.
Thanks everyone for all the suggestions and comments. |
Scope delegation (
.value
lookup) is one of more trickier aspects of build.sbt DSL. This writeup builds on top of the existing Scopes page, and breaks down the notion of scope delegation into rules and a few realistic looking examples.