简体   繁体   English

Scala多模块项目?

[英]Scala multi-module project?

  • I have Java background and thinking of learning Scala . 我有Java背景并且有学习Scala想法。
  • One of this things that I like about using Maven is that I can make a project as multi-maven module. 我喜欢使用Maven其中一件事是,我可以将项目制作为多Maven模块。 Example? 例?
 Project/pom.xml /persistence/pom.xml /business/pom.xml /services/pom.xml 

The nice thing about it is that each of these modules can have their own dependencies and they can be tested independently, rather than running one monolith application. 令人高兴的是,每个模块都可以具有自己的依赖性,并且可以独立测试它们,而不用运行一个整体应用程序。

How do we achieve something similar in Scala , sbt or its ecosystem? 我们如何在Scalasbt或其生态系统中实现类似的sbt

You can definitely do it. 你绝对可以做到的。 It's called SBT Multi-Project build . 这就是所谓的SBT Multi-Project build You can define one master project and multiple child projects with something like this (from the docs link above): 您可以使用以下内容定义一个主项目和多个子项目(来自上面的docs链接):

import sbt._
import Keys._

object HelloBuild extends Build {
    lazy val root = Project(id = "hello",
                            base = file(".")) aggregate(foo, bar)

    lazy val foo = Project(id = "hello-foo",
                           base = file("foo"))

    lazy val bar = Project(id = "hello-bar",
                           base = file("bar"))
}

Each project can be built separately, you can also package each into a separate JAR, or combine them all into a single master JAR. 每个项目都可以单独构建,也可以将每个项目打包到一个单独的JAR中,或者将它们全部组合到一个主JAR中。 Each project can define it's own dependencies, but they can also be shared if needed. 每个项目都可以定义自己的依赖关系,但是如果需要,也可以共享它们。 Basically you have full control. 基本上,您可以完全控制。 Take a look at my project build file here for example. 例如, 在这里查看我的项目构建文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM