我试图在我的macbook上安装SBT.当我运行它时,它不会询问我任何项目定义(例如标题)并简单地说
[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
Run Code Online (Sandbox Code Playgroud)
然后它转到看起来像sbt解释器.
当我查看"test2"时,有一个项目和目标目录,但我没有看到要使用的src目录
很明显我在安装的某个地方出了问题,但我不确定在哪里.有任何想法吗?
更新
所以我刚刚在新的fedora安装上安装了0.10.我得到完全相同的问题,相同的"信息"消息,它只创建了一个项目和目标目录
我一定是在做一些愚蠢的事吗?我究竟做错了什么?:p
Jac*_*ski 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]>
Run Code Online (Sandbox Code Playgroud)
引用从SBT的官方文档开始运行.
在没有命令行参数的情况下运行sbt会以交互模式启动它.交互模式具有命令提示符(具有选项卡完成和历史记录!).
在你的情况下,当你开始sbt in /Users/qui/Documents/Programming/test2/
it默认它是项目目录并应用默认设置.
以下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
Run Code Online (Sandbox Code Playgroud)
(我已经更改了提示,因此项目的名称,即已启动的目录sbt的名称,显示在之前>
).
您可以使用" 评估设置 " 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
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
build.sbt
然后,该文件将包含所有设置,就好像首先在那里设置一样.
$ cat build.sbt
name := "My test2 sbt project"
version := "1.0"
scalaVersion := "2.10.3"
Run Code Online (Sandbox Code Playgroud)
默认情况下,sbt在target
目录中创建各种文件.当您查看target
目录内部时,没有文件 - 只是一个空目录.这同样适用于project
也可能存在或不存放target
目录.它们被认为是可用的,如果没有,它们是默认创建的.
当您在sbt的交互式shell(with 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/)
Run Code Online (Sandbox Code Playgroud)
执行此操作后,将build.sbt
保存具有您自己设置的a .这可能是进一步配置项目的良好起点.
jacek:~/sandbox/stackoverflow/test2
$ cat build.sbt
scalaVersion := "2.10.3"
Run Code Online (Sandbox Code Playgroud)
Typesafe Activator是一个基于浏览器或命令行的工具,可帮助开发人员开始使用Typesafe Reactive Platform.
在封面下,Activator是一个在sbt上面构建的UI,由Josh Suereth在截屏视频中介绍sbt 0.13.2.
看来,这是在Activator中提供的众多模板中设置sbt项目的唯一有福的解决方案.
如果你需要一些帮助来布局目录结构并有一个现成的项目设置,你可能想使用giter8这是一个命令行工具来应用github上定义的模板
比如说,您想要创建一个具有scalaz依赖项的项目.您可能想要使用adinapoli/scalaz-revolver(请参阅可用模板列表).
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
Run Code Online (Sandbox Code Playgroud)
请参阅使用源代码创建项目目录以了解更多信息.
正如下面@ 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")
Run Code Online (Sandbox Code Playgroud)在中定义自定义全局覆盖~/.sbt/0.13/np.sbt
.将以下内容添加到文件中.
seq(npSettings:_*)
(NpKeys.defaults in (Compile, NpKeys.np)) ~= {
_.copy(org="me.lessis", version="0.1.0-SNAPSHOT")
}
Run Code Online (Sandbox Code Playgroud)使用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"
Run Code Online (Sandbox Code Playgroud)不,你没有做错什么,以前版本的 sbt (0.7.x) 确实询问你是否要创建项目。
sbt 版本 0.10.x 是完全重写的,并且行为方式不同(即要求您在启动时创建一个项目)。
旧项目位于 googlecode 上,但现已转移到 github,您可以在https://github.com/harrah/xsbt/wiki找到 0.10.x 的文档,特别是https://github.com/harrah/xsbt /wiki/Settings(如果您来自 0.7.x 背景)。
一开始你会觉得新的设置系统有点难以理解,但请相信我,你会喜欢它的:)
归档时间: |
|
查看次数: |
6114 次 |
最近记录: |