sbt为什么不创建项目文件?

| 我试图在Macbook上安装SBT。当我运行它时,它不会询问我任何项目定义(例如标题),只是说
[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
然后转到看起来像sbt解释器的地方。 当我查看\“ test2 \”的内部时,有一个项目和目标目录,但是没有看到要使用的src目录 显然,我在安装中的某个地方出错了,但是我不确定在哪里。有任何想法吗? 更新资料 因此,我刚刚在全新的fedora安装中安装了0.10。而且我得到了完全相同的问题,相同的“ info”消息,它只创建了一个项目和目标目录 我一定在做一些愚蠢的事吧?我究竟做错了什么? :p     
已邀请:
        不,您没有做错什么,以前版本的sbt(0.7.x)确实询问您是否要创建项目。 sbt版本0.10.x是完整的重写,其行为方式不同(即要求您在启动时创建项目)。 旧项目位于googlecode上,但此后移至github,您可以在https://github.com/harrah/xsbt/wiki(尤其是https://github.com/harrah/xsbt)上找到0.10.x的文档/ wiki / Settings(如果您来自0.7.x背景)。 首先,将您的头放在新的设置系统上有些困难,但是当我说您会喜欢它时,请相信我:)     
我使用SBT 0.13工作,所以...您的里程可能会有所不同。 sbt \的默认行为 您遇到的是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的官方文档中的运行。   在没有命令行参数的情况下运行sbt以交互方式启动它   模式。交互模式具有命令提示符(带有制表符补全和   历史!)。 例 在您的情况下,当您在ѭ2中启动sbt时,它默默地假定它是项目目录并应用了默认设置。 以下sbt会话也位于
test2
目录中。我使用ѭ4display显示设置键的帮助,然后使用键显示其值。
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目录的名称)显示在“ 6”之前)。 您可以使用“ 7”命令来更改键的值,该命令可以评估设置并将其应用于当前项目。
[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
在关于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
目录时,没有文件-只是一个空目录。同样的内容适用于可能也可能不包含
target
目录的
project
。假定它们可用,如果没有,默认情况下会创建它们。 当您在sbt \的交互式外壳程序中更改设置(使用
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\"
Typesafe激活器 根据Typesafe Activator的主页:   Typesafe Activator是基于浏览器或命令行的工具,可以帮助   开发人员开始使用Typesafe Reactive Platform。 在幕后,Activator是由Josh Suereth在屏幕快照sbt 0.13.2介绍中演示的sbt之上构建的UI。 看来,这是在Activator中可用的众多模板中唯一可以设置sbt项目的解决方案。 giter8-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
请参阅使用源代码创建项目目录以了解更多信息。 NP-新的sbt项目生成变得简单(r) 如下面@ 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\"
    
        如np插件自述文件所述,所需步骤为:
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
...开始编码     
        一线创建目录结构和文件(全部为空):
mkdir -p ./src/{main,test}/{scala,java,resources}; mkdir project; touch build.sbt; touch project/build.properties
    
        我发现并更新了Alvin Alexander(惊人的Scala Cookbook的作者)编写的脚本,该脚本可以完成您想要的事情。 我再次提供一个bash脚本,因为创建目录和文件的任务既繁琐又简单。为此制作一个完整的SBT插件实在是太过分了。
This script creates an SBT project directory beneath the current directory.

Directory/Project Name (MyFirstProject): ProjectX
Create .gitignore File? (Y/n):
Create README.md File? (Y/n):

-----------------------------------------------
Directory/Project Name: ProjectX
Create .gitignore File?: y
Create README.md File?: y
-----------------------------------------------
Create Project? (Y/n):

Project created. See the following URL for build.sbt examples:
http://alvinalexander.com/scala/sbt-syntax-examples

$ cat build.sbt
name := \"ProjectX\"

version := \"1.0\"

scalaVersion := \"2.11.7\"

$
最后,我相信在没有任何参数的情况下启动的SBT应该与该脚本完全一样。     

要回复问题请先登录注册