Need advice on project layout for Play 2.2 submodule with other modules as dependencies

前端 未结 2 778
忘掉有多难
忘掉有多难 2021-02-09 07:48

I have an existing SBT project with modules. I want to add Play 2.2 into my project as a submodule. This new Play module will depend on other modules.

What I found so fa

2条回答
  •  梦谈多话
    2021-02-09 07:52

    Two options:

    1) have an 'empty' main project aggregating your 3 sub-projects:

    root
    \--- project
        \--- Build.scala
    \--- web_ui
    \--- common
    \--- desktop_ui
    

    And in Build.scala something like this:

    lazy val common = Project(id = "common", base = file("common"))
    lazy val desktopUi = Project(id = "desktop_ui", base = file("desktop_ui")
    lazy val webUi = play.Project(name = "web_ui", path = file("web_ui"))
    .dependsOn(common, desktopUi)
    

    lazy val root = Project(id = "root", base = file(".")).aggregate(common, desktopUi, webUi)

    With this option, you can start sbt from the root folder and build all your projects. You also define all the settings, dependencies in this unique build definition.

    2) Another layout can be used to keep your sub-projects independent from each other. I tend to prefer this way because it's cleaner (e.g. I can work on common as an independent project, not as a submodule) but it is not as convenient to build the whole system.

    root
    \--- web_ui
        \--- project
            \--- Build.scala
    \--- common
         \--- project
            \--- Build.scala
    \--- desktop_ui
         \--- project
            \--- Build.scala
    

    Here, each project is independent (you can use build.sbt instead of Build.scala if you want, see sbt documentation) and in web_ui/project/Build.scala :

    lazy val common = RootProject(file("../common"))
    lazy val desktopUi = RootProject(file("../desktop_ui"))
    
    val main = play.Project(name = "web_ui", path = file("web_ui")).dependsOn(common, desktopUi) 
    

    Here, root is just used to gather everything in one folder, then the play project references the other modules.

提交回复
热议问题