我尝试在我的 MacBook 上安装 SBT。当我运行它时,它不会询问我任何项目定义(例如标题),只是说“
[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
然后它会转到 sbt 解释器”。
当我查看“test2”内部时,有一个项目和目标目录,但我没有看到可以使用的 src 目录
,显然我在安装中的某个地方出了问题,但我不确定在哪里。有什么想法吗?
更新
所以我刚刚在全新的 Fedora 安装上安装了 0.10。我遇到了完全相同的问题,相同的“信息”消息,它只创建了一个项目和目标目录,
我一定是在做一些愚蠢的事情,对吗?我做错了什么? :p
I have tried to install SBT on my macbook. When I run it, it doesn't ask me for any project definitions (e.g. title) and simply says
[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
It then goes to what looks like the sbt interpreter.
When I look inside "test2", there is a project and target directory but I dont see a src directory to work with
Clearly I have gone wrong somewhere in my installation but I'm unsure where. Any ideas?
Update
So I just installed 0.10 on a fresh fedora install. And I am getting the exact same problem, same "info" message and it has only created a project and target directory
I must be doing something idiotic right? What am I doing wrong? :p
发布评论
评论(5)
我使用 SBT 0.13,所以...您的里程可能会有所不同。
sbt 的默认行为
你所经历的是 sbt 的默认行为。该工具期望项目文件已经就位,或者当没有项目文件时,它不会创建它们 - 默认值仅应用于当前目录,该目录实际上成为按名称调用的项目的项目目录然后 SBT 打开 sbt shell。
引用 SBT 官方文档中的 Running 。
示例
在您的情况下,当您在
/Users/qui/Documents/Programming/test2/
中启动 sbt 时,它会默默地假定它是项目目录并应用默认设置。以下 sbt 会话也位于 test2 目录中。我使用
help
显示设置键的帮助,然后使用该键显示其值。(我更改了提示,以便项目的名称(即 sbt 启动的目录的名称)显示在
>
之前)。您可以使用
set
命令更改键的值,该命令评估设置并将其应用到当前项目。com/a/12781664/1305344">StackOverflow 上的另一个问题 @regis-jean-gilles 展示了如何使用
set
设置其他设置命令。然后,
build.sbt
文件将包含所有设置,就像一开始就在那里设置一样。默认情况下,sbt 在
target
目录中创建各种文件。当您查看target
目录时,会发现没有文件 - 只有一个空目录。这同样适用于也可能包含也可能不包含target
目录的project
。假定它们可用,如果不可用,则默认创建它们。当您更改 sbt 交互式 shell 中的设置(使用
set
)时,您可以使用session save
保存会话。完成此操作后,将保存带有您自己的设置的
build.sbt
。这可能是进一步配置项目的良好起点。Typesafe Activator
根据Typesafe Activator 主页:
在幕后,Activator 是一个构建在 sbt 之上的 UI,由 Josh Suereth 在截屏视频 sbt 简介0.13.2。
看起来,这是 Activator 中提供的众多模板中唯一用于设置 sbt 项目的解决方案。
giter8 - sbt 项目(布局)模板
如果您需要一些帮助来布局目录结构并有一个现成的项目设置,您可能需要使用 giter8 这是一个用于应用 github 上定义的模板的命令行工具
比如说,您想使用 scalaz 依赖项。您可能需要使用 adinapoli/scalaz-revolver (请参阅可用模板列表)。
请参阅创建包含源代码的项目目录来查找出去更多。
np - 新的 sbt 项目生成变得简单(r)
正如下面 @0__ 的评论所指出的,还有另一个项目旨在简化 sbt 中新项目的创建方式 - np.这似乎正是您所需要的。
在 https://github.com/softprops/np#for-sbt-013 有一个完整的描述,说明了使用该实用程序进行设置和创建新的 sbt 项目所需的内容,可归结为:
注册 sbt 插件。将以下内容添加到
~/.sbt/0.13/plugins/np.sbt
。在
~/.sbt/0.13/np.sbt
中定义自定义全局覆盖。将以下内容添加到文件中。使用 np 插件的命令 -
np
。为 sbt 项目创建一个空目录并运行 sbt np。I work with SBT 0.13 so...your mileage may vary.
sbt's default behaviour
What you experience is the default behaviour of sbt. The tool expects that the project files are already in place or when there is no project files it doesn't bother to create them - the default values are just applied to the current directory that effectively becomes the project directory for a project called by the name of the directory it's in. SBT then opens sbt shell.
Quoting Running from the official documentation of SBT.
Example
In your case, when you started sbt in
/Users/qui/Documents/Programming/test2/
it silently assumed it's the project directory and applied the default settings.The following sbt session is in
test2
directory, too. I usehelp
to display the help of a setting key and then use the key to display its value.(I've changed the prompt so the name of the project, i.e. the name of the directory sbt has been started in, is displayed before the
>
).You can change the value of a key with the
set
command that Evaluates a Setting and applies it to the current project.In the other question on StackOverflow @regis-jean-gilles has showed how to set the other settings using the
set
command.The
build.sbt
file will then contain all the settings as if there'd been set there in the first place.By default, sbt creates various files in
target
directory. When you look inside thetarget
directory, there are no files - just an empty directory. The same applies toproject
that also may or may not holdtarget
directory. They're assumed to be available and if there's not, they're created by default.When you change a setting in sbt's interactive shell (with
set
), you can save the session withsession save
.Once you do that, a
build.sbt
with your own setting(s) is saved. That might be a good starting point for further configuration of a project.Typesafe Activator
According to the home page of Typesafe Activator:
Under the covers, Activator is a UI built atop of sbt as demo'ed by Josh Suereth in the screencast Introducing sbt 0.13.2.
It appears that that's the only blessed solution for setting up sbt projects out of the many templates available in Activator.
giter8 - sbt project (layout) templates
If you however need some help to lay out the directory structure and have a ready-to-use project setup, you may want to use giter8 that's a command line tool to apply templates defined on github
Say, you want to create a project with scalaz dependency. You may want to use adinapoli/scalaz-revolver (see the list of available templates).
See Create a project directory with source code to find out more.
np - new sbt project generation made simple(r)
As pointed out in the comments by @0__ below, there's another project that aims at simplifying how new projects in sbt are created - np. That seems exactly what you needed.
In https://github.com/softprops/np#for-sbt-013 there's a complete description of what's needed to set it up and create new sbt projects using the utility that boils down to:
Registering the sbt plugin. Add the following to
~/.sbt/0.13/plugins/np.sbt
.Define a custom global overrides in
~/.sbt/0.13/np.sbt
. Add the following to the file.Use the np plugin's command -
np
. Create an empty directory for the sbt project and runsbt np
.不,你没有做错什么,以前版本的 sbt (0.7.x) 确实询问你是否要创建项目。
sbt 版本 0.10.x 是完全重写的,并且行为方式不同(即要求您在启动时创建一个项目)。
旧项目位于 googlecode 上,但现已转移到 github,您可以在 https: //github.com/harrah/xsbt/wiki,特别是https://github.com/harrah/xsbt/wiki/Settings(如果您来自 0.7.x 背景)。
一开始你会觉得新的设置系统有点难以理解,但请相信我,你会喜欢它的:)
No you're not doing something wrong, previous versions of sbt (0.7.x) did ask you if you wanted to create your project.
sbt version 0.10.x is a complete rewrite and does not act the same way (i.e. ask you to create a project on startup).
The old project was on googlecode but has since moved to github, you can find the documentation for 0.10.x at https://github.com/harrah/xsbt/wiki, in particular https://github.com/harrah/xsbt/wiki/Settings if you come from a 0.7.x background.
It's a bit hard to wrap your head around the new settings system at first, but trust me when I say you'll love it :)
如 np 插件 自述文件中所述,所需的步骤是:
... 开始编码
As described in the np plugin readme, the required steps would be :
... start coding
一行创建目录结构和文件(全部为空):
One-liner to create the directory-structure and files (all empty):
我发现并更新了 Alvin Alexander(令人惊叹的书 Scala Cookbook 的作者)的 脚本,它的作用只是你想要什么。
我再次提供了一个 bash 脚本,因为创建目录和文件的任务很迂腐,但很简单。为此,为 SBT 制作一个成熟的插件是一种矫枉过正的行为。
最后,我相信在没有任何参数的情况下启动的 SBT 应该像这个脚本一样完全。
I found and updated a script by Alvin Alexander (author of the amazing book Scala Cookbook) that does just what you want.
Once again, I provide a bash script because the task of creating the directories and the files is pedantic, but simple. Making a full fledged plugin for SBT for this is an overkill.
And finally, I believe SBT launched without any arguments should behave exactly like this script.