在Scala中将模块项目设置为sbt项目? [英] Setting a module project in Scala as an sbt project?

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

问题描述

我想知道如何将常规scala项目转换为sbt项目。我已经尝试在根目录上手动创建一个sbt文件,正确实现,但是Intellij仍然不认识这是一个sbt项目,也就是说,它不会在视图 - >工具Windows中显示SBT 选项。

I'd like to know how to convert a regular scala project into an sbt project. I've tried manually creating an sbt file on the root directory, correctly implemented, but Intellij still doesn't recognize this as a sbt project, i.e, it won't show me in the "View -> Tool Windows" the "SBT" option.

我应该怎么做?我实际上要做的是创建一个包含多个(独立)模块的空项目。

How should I go about this? What I'm actually attempting to do is to create an empty project with multiple (independent) modules.

从我收集到的内容似乎无法添加一个模块直接支持sbt,我是对吗?

From what I've gathered there seems to be no way to add a module directly with sbt support, am I right?

谢谢

推荐答案

这是一个多项目构建的示例。根项目聚合它们以防万一你想要将它们全部编译在一起或将它们打包在一起等等。coreLibrary项目取决于coreA和coreB的代码。

Here is an example of a multi-project build. The root project "aggregates" them all in case you want to compile them all together or package them all together, etc. The "coreLibrary" project depends on the code of "coreA" and "coreB".

import sbt.Keys._
import sbt._

name := "MultiProject"

lazy val root = project.in(file(".")).aggregate(coreA, coreB, coreLibrary)

lazy val coreA = Project("CoreA", file("core-a")).settings(
  organization := "org.me",
  version := "0.1-SNAPSHOT"
)

lazy val coreB = Project("CoreB", file("core-b")).settings(
  organization := "org.me",
  libraryDependencies += "org.apache.kafka" %% "kafka" % "0.8.2-beta",
  version := "0.3-SNAPSHOT"
)

lazy val coreLibrary = Project("UberCore", file("core-main")).dependsOn(coreA, coreB).settings(
  organization := "org.me",
  version := "0.2-SNAPSHOT"
)

您可以(例如)从命令行编译每个项目:

You can (for example) compile each project from the command line:

>sbt CoreB/compile

或者您可以以交互方式执行此操作:

Or you can do this interactively:

>sbt
>project CoreB
>compile

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

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