使用SBT创建新的Scala项目?

时间:2014-03-14 10:02:20

标签: scala sbt

我可以像这样创建一个sbt项目:

$ mkdir project1
$ cd project1
$ sbt
Loading /usr/share/sbt/bin/sbt-launch-lib.bash

> set name := "project1"
[info] Defining *:name
...

> set scalaVersion :="2.10.2"
[info] Defining *:scalaVersion
...

> set version :="1.0"
[info] Defining *:version
...

> session save
[info] Reapplying settings...

> exit

这会为项目创建build.sbt个文件。

$ cat build.sbt 
name := "project1"

scalaVersion :="2.10.2"

version :="1.0"

现在是否有任何命令行来做同样的事情?类似的东西:

sbt new_project "name" version scala_version

EDIT1

我想出了另一种方法,即创建项目文件夹:

$ mkdir project1
$ cd project1/

更新项目详情:

$ sbt 'set name := "project1"' 'set scalaVersion :="2.10.2"' 'set version :="1.0"' 'session save'
Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:name
[info] The new value will be used by *:description, *:normalizedName and 6 others.
[info]  Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:ivyScala and 10 others.
[info]  Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:version
[info] The new value will be used by *:isSnapshot, *:projectId and 3 others.
[info]  Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)

我们已生成项目并保存设置:

$ ls
build.sbt  project
$ cat build.sbt 
name := "project1"

scalaVersion :="2.10.2"

version :="1.0"

我希望SBT本身提供Maven中的功能:mvn archetype:generate

3 个答案:

答案 0 :(得分:4)

SBT有一个np插件,可以帮助您完成任务。用法:

$ sbt 
$ np name:my-new-project org:org.myproject version:0.1.0-SNAPSHOT  

答案 1 :(得分:3)

从sbt 0.13.13开始,有一个内置命令@Test(dataProvider="myData", DataProviderClass=MyDataProvider.class, groups=MyGroups.getGroups()) public void test() { //... }

new

答案 2 :(得分:2)

您可能想查看我的项目skeleton

当您需要快速启动并运行时,它可以简化第一步。