Scala多模块项目? [英] Scala multi-module project?

查看:396
本文介绍了Scala多模块项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我有 Java 背景,并考虑学习 Scala

  • 我喜欢使用 Maven 的一件事就是我可以把项目作为多个maven模块。例?




  Project / pom.xml 
/ persistence /pom.xml
/business/pom.xml
/services/pom.xml


关于它的好处是这些模块中的每一个都可以拥有自己的依赖项,并且可以独立测试,而不是运行一个整体应用程序。



我们如何在 Scala sbt 或其生态系统?

解决方案

你绝对可以做到。它被称为 SBT多项目构建 。您可以使用以下内容定义一个主项目和多个子项目(来自上面的文档链接):

  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))
}

每个项目都可以单独构建,也可以将每个项目打包成一个单独的JAR,或者将它们全部组合成一个主JAR。每个项目都可以定义自己的依赖项,但如果需要,也可以共享它们。基本上你有完全的控制权。例如,查看我的项目构建文件此处。 / p>

  • I have Java background and thinking of learning Scala.
  • One of this things that I like about using Maven is that I can make a project as multi-maven module. 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?

解决方案

You can definitely do it. It's called SBT Multi-Project build. You can define one master project and multiple child projects with something like this (from the docs link above):

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. 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.

这篇关于Scala多模块项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆