Sbt 为什么';是否创建项目文件?

Sbt 为什么';是否创建项目文件?,sbt,Sbt,我已尝试在我的macbook上安装SBT。当我运行它时,它不会要求我提供任何项目定义(例如标题),而是简单地说 [info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/) 然后它会转到看起来像sbt解释器的程序 当我查看“test2”内部时,有一个项目和目标目录,但我没有看到一个src目录 很明显,我在安装中的某个地方出了问题,但我不确定在哪里。有什么想法吗 更新 所

我已尝试在我的macbook上安装SBT。当我运行它时,它不会要求我提供任何项目定义(例如标题),而是简单地说

[info] Set current project to default (in build file:/Users/qui/Documents/Programming/test2/)
然后它会转到看起来像sbt解释器的程序

当我查看“test2”内部时,有一个项目和目标目录,但我没有看到一个src目录

很明显,我在安装中的某个地方出了问题,但我不确定在哪里。有什么想法吗

更新

所以我刚在新的fedora上安装了0.10。我得到了完全相同的问题,相同的“信息”消息,它只创建了一个项目和目标目录


我一定是在做傻事,对吧?我做错了什么p

不,您没有做错什么,以前版本的sbt(0.7.x)确实问过您是否要创建项目

sbt版本0.10.x是一个完整的重写,其行为方式不同(即要求您在启动时创建项目)

以前的项目是在googlecode上完成的,但后来转移到github,您可以在上找到0.10.x的文档,特别是如果您来自0.7.x背景


一开始你很难理解新的设置系统,但相信我,当我说你会喜欢它时:)

我使用的是SBT 0.13,所以……你的里程数可能会有所不同

sbt的违约行为 您所体验到的是sbt的默认行为。该工具希望项目文件已经存在,或者当没有项目文件时,它不需要费心创建它们-默认值仅应用于当前目录,该目录实际上成为项目的项目目录,该项目以其所在目录的名称命名。然后,SBT打开SBT外壳

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会在interactive中启动它 模式交互模式有一个命令提示符(带制表符完成和 历史!)

例子 在您的例子中,当您在
/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的名称)

您可以使用
set
命令更改键的值,该命令用于评估设置并将其应用于当前项目

然后,
build.sbt
文件将包含所有设置,就好像当初在那里设置的一样

$ cat build.sbt
name := "My test2 sbt project"

version := "1.0"

scalaVersion := "2.10.3"
默认情况下,sbt在
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/)
类型安全激活器 根据:

Typesafe Activator是一种基于浏览器或命令行的工具,有助于 开发人员开始使用Typesafe反应式平台

在封面下,由Josh Suereth在屏幕上演示

在Activator中提供的许多模板中,这似乎是设置sbt项目的唯一幸运的解决方案

giter8-sbt项目(布局)模板 但是,如果您需要一些帮助来布局目录结构和准备好使用的项目设置,您可能希望使用这是一个命令行工具来应用github上定义的模板

比如说,您想要创建一个具有依赖关系的项目。您可能需要使用(请参阅)

请查看以了解更多信息

np-简化新sbt项目生成(r) 正如下面@0__;的评论所指出的,还有一个项目旨在简化sbt中新项目的创建方式。这似乎正是你所需要的

在中,有一个完整的描述,说明了使用该实用程序设置和创建新的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"
    
  • 如自述文件所述,所需步骤如下:

    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
    
    。。。开始编码

    我找到并更新了阿尔文·亚历山大(著名书籍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应该像这个脚本一样运行。

    一行代码来创建目录结构和文件(都是空的):


    你的sbt脚本的内容是什么?我的是:java-Xmx1512M-XX:+cmsclasssUnloadingEnabled-XX:MaxPermSize=512m-Dsbt.log.noformat=true-jar
    dirname$0
    /sbt-launch.jar“$@”。我已经安装了0.11.3版本,但仍然出现了与qui相同的问题……我找不到如何修复它的其他两个选项。(1) 这个。(2) 从sbt shell配置并保存。例如,
    >设置libraryDependencies+=“org.scalaz”%%“scalaz核心”%%“7.0.5”
    ,然后
    >会话保存
    。您已经有了基本的
    build.sbt
    。谢谢@0。我根据你的建议改变了答案。现在好多了!荣誉+10,谢谢你的列表,t
    seq(npSettings:_*)
    
    (NpKeys.defaults in (Compile, NpKeys.np)) ~= {
      _.copy(org="me.lessis", version="0.1.0-SNAPSHOT")
    }
    
    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"
    
    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
    
    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"
    
    $
    
    mkdir -p ./src/{main,test}/{scala,java,resources}; mkdir project; touch build.sbt; touch project/build.properties