我曾尝试在我的macbook上安装SBT。当我运行它时,它不会询问我任何项目定义(例如标题)并简单地说
[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
然后转到看起来像sbt解释器。
当我查看“test2”时,有一个项目和目标目录,但我没有看到可以使用的src目录
显然我在安装的某个地方出了问题,但我不确定在哪里。有什么想法吗?
更新
所以我刚刚在一个新的fedora安装上安装了0.10。我得到完全相同的问题,相同的“信息”消息,它只创建了一个项目和目标目录
我必须做一些愚蠢的事吗?我究竟做错了什么? :P
答案 0 :(得分:24)
我使用 SBT 0.13 ,所以......你的里程可能会有所不同。
您遇到的是sbt的默认行为。该工具期望项目文件已经到位,或者当没有项目文件时,它不打算创建它们 - 默认值只应用于当前目录,该目录实际上成为名称调用的项目的项目目录它所在的目录。然后SBT打开sbt shell。
jacek:~/sandbox/stackoverflow/testaaa
$ tree
.
0 directories, 0 files
jacek:~/sandbox/stackoverflow/testaaa
$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to testaaa (in build file:/Users/jacek/sandbox/stackoverflow/testaaa/)
[testaaa]>
从SBT的官方文件中引用Running。
在没有命令行参数的情况下运行sbt会在交互式中启动它 模式。交互模式有一个命令提示符(选项卡完成和 历史!)。
在你的情况下,当你在/Users/qui/Documents/Programming/test2/
开始sbt时,它默默地认为它是项目目录并应用了默认设置。
以下sbt会话也位于test2
目录中。我使用help
显示设置键的帮助,然后使用键显示其值。
jacek:~/sandbox/stackoverflow/test2
$ tree
.
0 directories, 0 files
jacek:~/sandbox/stackoverflow/test2
$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to test2 (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> help name
Project name.
[test2]> name
[info] test2
[test2]> help organization
Organization/group ID.
[test2]> organization
[info] default
[test2]> help version
The version/revision of the current module.
[test2]> version
[info] 0.1-SNAPSHOT
[test2]> help scalaVersion
The version of Scala used for building.
[test2]> scalaVersion
[info] 2.10.2
(我已经更改了提示,因此项目名称,即目录sbt的名称已经开始,显示在>
之前)。
您可以使用{em>评估设置的set
命令更改密钥的值,并将其应用于当前项目。
[test2]> help set
set [every] <setting-expression>
Applies the given setting to the current project:
1) Constructs the expression provided as an argument by compiling and loading it.
2) Appends the new setting to the current project's settings.
3) Re-evaluates the build's settings.
This command does not rebuild the build definitions, plugins, or configurations.
It does not automatically persist the setting(s) either.
To persist the setting(s), run 'session save' or 'session save-all'.
If 'every' is specified, the setting is evaluated in the current context
and the resulting value is used in every scope. This overrides the value
bound to the key everywhere.
[test2]> set scalaVersion := "2.10.3"
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:dependencyUpdatesData and 11 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to test2 (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> scalaVersion
[info] 2.10.3
在the other question on StackOverflow @regis-jean-gilles中展示了如何使用set
命令设置其他设置。
[test2]> set name := "My test2 sbt project"
[info] Defining *:name
[info] The new value will be used by *:description, *:normalizedName and 8 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to My test2 sbt project (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> set version := "1.0"
[info] Defining *:version
[info] The new value will be used by *:isSnapshot, *:projectId and 5 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to My test2 sbt project (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> set scalaVersion := "2.10.3"
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:dependencyUpdatesData and 11 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to My test2 sbt project (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> session save
[info] Reapplying settings...
[info] Set current project to My test2 sbt project (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
[test2]> exit
然后build.sbt
文件将包含所有设置,就好像首先在那里设置一样。
$ cat build.sbt
name := "My test2 sbt project"
version := "1.0"
scalaVersion := "2.10.3"
默认情况下,sbt在target
目录中创建各种文件。当你查看target
目录时,没有文件 - 只是一个空目录。这同样适用于project
,它也可能包含或不包含target
目录。它们被认为是可用的,如果没有,它们是默认创建的。
当您更改sbt交互式shell中的设置(使用set
)时,您可以使用session save
保存会话。
[test2]> help session
session <command>
Manipulates session settings, which are temporary settings that do not persist past the current sbt execution (that is, the current session).
Valid commands are:
clear, clear-all
Removes temporary settings added using 'set' and re-evaluates all settings.
For 'clear', only the settings defined for the current project are cleared.
For 'clear-all', all settings in all projects are cleared.
list, list-all
Prints a numbered list of session settings defined.
The numbers may be used to remove individual settings or ranges of settings using 'remove'.
For 'list', only the settings for the current project are printed.
For 'list-all', all settings in all projets are printed.
remove <range-spec>
<range-spec> is a comma-separated list of individual numbers or ranges of numbers.
For example, 'remove 1,3,5-7'.
The temporary settings at the given indices for the current project are removed and all settings are re-evaluated.
Use the 'list' command to see a numbered list of settings for the current project.
save, save-all
Makes the session settings permanent by writing them to a '.sbt' configuration file.
For 'save', only the current project's settings are saved (the settings for other projects are left alone).
For 'save-all', the session settings are saved for all projects.
The session settings defined for a project are appended to the first '.sbt' configuration file in that project.
If no '.sbt' configuration file exists, the settings are written to 'build.sbt' in the project's base directory.
[test2]> session save
[info] Reapplying settings...
[info] Set current project to test2 (in build file:/Users/jacek/sandbox/stackoverflow/test2/)
执行此操作后,将保存具有您自己设置的build.sbt
。这可能是进一步配置项目的良好起点。
jacek:~/sandbox/stackoverflow/test2
$ cat build.sbt
scalaVersion := "2.10.3"
根据the home page of Typesafe Activator:
Typesafe Activator是一个基于浏览器或命令行的工具,可以提供帮助 开发人员开始使用Typesafe Reactive Platform。
封面,Activator is a UI built atop of sbt由Josh Suereth在截屏视频Introducing sbt 0.13.2中演示。
似乎这是在Activator中提供的众多模板中设置sbt项目的唯一有福的解决方案。
如果您需要一些帮助来布局目录结构并具有可立即使用的项目设置,您可能需要使用giter8 命令行工具来应用在github上定义的模板
说,您想要创建一个scalaz依赖项目。您可以使用adinapoli/scalaz-revolver(请参阅the list of available templates)。
jacek:~/sandbox/stackoverflow
$ g8 adinapoli/scalaz-revolver
Simple scala project with sbt-revolver
organization [org.example]: pl.japila
name [Scala sbt-revolver project]:
scala_version [2.9.2]: 2.10.3
version [0.1-SNAPSHOT]:
Template applied in ./scala-sbt-revolver-project
jacek:~/sandbox/stackoverflow
$ cd scala-sbt-revolver-project/
jacek:~/sandbox/stackoverflow/scala-sbt-revolver-project
$ tree
.
├── README
├── build.sbt
├── project
│ ├── Build.scala
│ ├── build.properties
│ └── plugins.sbt
└── src
└── main
└── scala
└── pl
└── japila
└── ScalaSbtrevolverProject.scala
6 directories, 6 files
请参阅Create a project directory with source code了解详情。
正如下面@ 0__的评论所指出的,还有另一个旨在简化sbt中新项目创建方式的项目 - np。这似乎正是你所需要的。
在https://github.com/softprops/np#for-sbt-013中,有一个完整的描述,说明使用该实用程序设置它并创建新的sbt项目所需的内容:
注册sbt插件。将以下内容添加到~/.sbt/0.13/plugins/np.sbt
。
addSbtPlugin("me.lessis" % "np" % "0.2.0")
在~/.sbt/0.13/np.sbt
中定义自定义全局覆盖。将以下内容添加到文件中。
seq(npSettings:_*)
(NpKeys.defaults in (Compile, NpKeys.np)) ~= {
_.copy(org="me.lessis", version="0.1.0-SNAPSHOT")
}
使用np插件的命令 - np
。为sbt项目创建一个空目录并运行sbt np
。
jacek:~/sandbox/stackoverflow
$ mkdir np-sandbox/
jacek:~/sandbox/stackoverflow
$ cd np-sandbox/
jacek:~/sandbox/stackoverflow/np-sandbox
$ sbt np
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to np-sandbox (in build file:/Users/jacek/sandbox/stackoverflow/np-sandbox/)
[info] Generated build file
[info] Generated source directories
[success] Total time: 0 s, completed Dec 7, 2013 12:51:42 PM
jacek:~/sandbox/stackoverflow/np-sandbox
$ tree
.
├── build.sbt
├── src
│ ├── main
│ │ ├── resources
│ │ └── scala
│ └── test
│ ├── resources
│ └── scala
└── target
└── streams
└── compile
└── np
└── $global
└── out
12 directories, 2 files
jacek:~/sandbox/stackoverflow/np-sandbox
$ cat build.sbt
organization := "me.lessis"
name := "default"
version := "0.1.0-SNAPSHOT"
答案 1 :(得分:3)
不,你没有做错什么,先前版本的sbt(0.7.x)确实问你是否要创建你的项目。
sbt版本0.10.x是完全重写并且行为方式不同(即要求您在启动时创建项目)。
旧项目在googlecode上,但后来转移到github,如果你来自0.7.x背景,你可以在https://github.com/harrah/xsbt/wiki找到0.10.x的文档,特别是https://github.com/harrah/xsbt/wiki/Settings。< / p>
一开始有点难以绕过新的设置系统,但是当我说你会喜欢它时相信我:)
答案 2 :(得分:3)
如np plugin自述文件所述,所需步骤为:
mkdir -p src/{main,test}/scala
touch build.sbt && vi build.sbt # fill in the basics (name, organization, version)
touch README.md && vi README.md
sbt
...开始编码
答案 3 :(得分:2)
创建目录结构和文件的一行代码(全部为空):
mkdir -p ./src/{main,test}/{scala,java,resources}; mkdir project; touch build.sbt; touch project/build.properties