Idiomatic way to write multi-project builds with .sbt files in sbt 0.13

前端 未结 1 1009
暖寄归人
暖寄归人 2021-01-30 13:54

I hear .sbt files have been improved in various ways in 0.13, and that now I can specify multi-project builds in them.

http://www.scala-sbt.org/0.13.0/docs/Community/Cha

相关标签:
1条回答
  • 2021-01-30 14:16

    It should already be the case in 0.12 that you can put .sbt files in the base directory of a subproject and the settings there will be included in that project's scope.

    Code is reused between .sbt files by creating a normal .scala file in project/. The code in project/ will be available for use in the .sbt files. The definitions in one .sbt are not visible to other .sbt files, at least in 0.13. This is mainly an implementation restriction and it is undetermined whether this will be lifted in future versions.

    The default root project will aggregate all subprojects, including those coming from projects defined in subProject/build.sbt.

    The current difficulty is making it explicit. For example, the following build.sbt in the root directory would define a subproject in sub/. This is a full definition, defining the ID, base directory, etc... for the project.

    <root>/build.sbt

    lazy val sub = project
    

    However, it cannot reference anything defined in <sub>/build.sbt. (The existence of sub/build.sbt is not known until after <root>/build.sbt is compiled and evaluated.) So, to explicitly define what sub aggregates, you'd need something like:

    sub/build.sbt

    lazy val sub = project.in(file(".")).aggregates(subSub)
    //or: lazy val sub = project in file(".") aggregate subSub
    
    lazy val subSub = project
    

    However, this duplicates the definition of sub.

    A possible solution going forward is to make the root definition just a reference, like:

    <root>/build.sbt

    lazy val sub = LocalProject("sub")
    
    0 讨论(0)
提交回复
热议问题