What is the difference between ThisBuild and Global scopes?

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

Can someone explain me the difference between writing these 2 lines:

resolvers in ThisBuild ++= appResolvers  resolvers in Global ++= appResolvers 

回答1:

Read Scopes for the full explanation.

I'll quote relevant parts:

There are three scope axes:

  • Projects
  • Configurations
  • Tasks

Scoping by project axis

If you put multiple projects in a single build, each project needs its own settings. That is, keys can be scoped according to the project.

Global scope

Each scope axis can be filled in with an instance of the axis type (for example the task axis can be filled in with a task), or the axis can be filled in with the special value Global.

Referring to scoped keys when running sbt

* can appear for each axis, referring to the Global scope.

  • {.}/test:full-classpath sets the project axis to "entire build" where the build is {.}. {.} can be written ThisBuild in Scala code.

Referring to scopes in a build definition

name in Global := "hello" 

(name in Global implicitly converts the scope axis Global to a scope with all axes set to Global; the task and configuration are already Global by default, so here the effect is to make the project Global, that is, define */*:name rather than {file:/home/hp/checkout/hello/}default-aea33a/*:name)

So as written above, Global sets all three axes to Global whereas ThisBuild sets only the project axis to {.}. This might make sense if you combine ThisBuild with other axis like configuration:

name> set name in Test in ThisBuild := "test-name" [info] Defining {.}/test:name 


回答2:

This would probably be used in a plugin:

resolvers in Global ++= appResolvers 

Whereas this could appear in your build definition:

resolvers in ThisBuild ++= appResolvers 

thereby letting you override global default offered by plugin.

Within the same build definition, using either one will most likely have equivalent effect, because they are the bottom two in the delegates list.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!