SBT 0.10和IDEA的初学者指南 [英] Beginner's guide to SBT 0.10 and IDEA

查看:128
本文介绍了SBT 0.10和IDEA的初学者指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SBT的新手,不确定如何启动项目。有人能指出我是创建Hello World类型项目的初学者指南,还是给我一些线索?

I'm new to SBT and am unsure how to get a project started. Can someone point me to a beginner's guide to creating a Hello World type project, or give me some clues?

我首选的IDE是IDEA。我根据上的说明运行 sbt-idea IDEA插件页面。目前我有点困惑,因为

My preferred IDE is IDEA. I have run sbt-idea according to the instruction on the IDEA Plugins page. At the moment I'm a bit confused because


  • 没有创建源文件夹 - 我应该在哪里/如何创建它们以及如何SBT会知道在哪里看吗?

  • 为什么它会尝试使用Scala 2.8.1,当我已经放入 scalaVersion:=2.9.0 build.sbt 文件中的code>?这意味着IDEA无法识别对象HelloWorld扩展App {}

  • 上面插件页面上的说明建议更改Before Launch 运行配置(包括默认运行配置)的选项。列出了不同的东西有13种不同的默认配置 - 哪一个要更改?我应该创建一个新的吗?这些默认配置仅适用于此项目,还是会对我不使用SBT的所有其他项目产生负面影响?

  • there are no source folders created - where / how am I supposed to create them and how will SBT know where to look?
  • why is it trying to use Scala 2.8.1, when I have already put scalaVersion := "2.9.0" in the build.sbt file? This means IDEA doesn't recognize object HelloWorld extends App {}.
  • the instructions on the plugins page above suggest changing the Before Launch options of "a Run Configuration (including the Default Run Configuration)". There are 13 different default configurations for different things listed - which one to change? Should I be creating a new one? Are these default configurations just for this project or will it adversely affect all my other projects that don't use SBT?

谢谢。

推荐答案

这对我有用:

首先获得sbt和gen-idea插件...

First get sbt and the gen-idea plugin going...


  1. 下载sbt-launch.jar并按照所述创建启动它的脚本SBT Github wiki

  2. 为您的新项目创建一个目录,例如(在linux上)〜/ myCode / myNewProject并更改到该目录

  3. 运行 sbt 命令。这应该下载scala库并创建一个'project'和'target'目录。

  4. 切换到'project'目录。

  5. 使用以下行在此目录中创建一个新文件'build.sbt',如 sbt-idea中所述插件Github wiki

  1. Download the sbt-launch.jar and create the script for launching it as described on the SBT Github wiki.
  2. Create a directory for your new project, such as (on linux) ~/myCode/myNewProject and change to that directory
  3. Run sbt command. This should download the scala libraries and create a 'project' and 'target' directories.
  4. Change to the 'project' directory.
  5. Create a new file 'build.sbt' in this directory with the following lines, as described on the sbt-idea plugin Github wiki:

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")


  • 更改回主项目目录,例如〜/ myCode / myNewProject。运行 sbt 。它应该下载gen-idea插件。

  • Change back to your main project directory such as ~/myCode/myNewProject. Run sbt. It should download the gen-idea plugin.

    现在获得IDEA SBT控制台插件......

    Now get the IDEA SBT console plugin going...


    1. 打开IDEA并从插件管理器安装SBT插件并重新启动IDEA。 (注意这是IDEA插件,而不是上面描述的sbt插件。)
      配置SBT插件如其维基上所述(运行配置,sbt-launch.jar的位置等)。

    2. 在IDEA中打开新生成的IDEA项目。

    3. 将您的代码和其他内容放在预期的默认目录中,如在目录布局下的sbt wiki 。您需要自己创建这些目录 - sbt不会自动创建它们。 'src'和'test'目录应该与sbt创建的'project'和'target'目录处于同一级别。

    4. 组成一个新的'build。 sbt'文件并将其放在〜/ myCode / myProject(或任何你称之为的)中。由于我只是搞清楚sbt,到目前为止我很简单 - 只提名scalatest作为依赖并使用Scala 2.9:

    1. Open IDEA and install the "SBT" plugin from the plugin manager and restart IDEA. (Note this is the IDEA plugin, not the sbt plugin described above.) Configure the SBT plugin as described on its wiki (run configurations, location of sbt-launch.jar etc).
    2. Open the freshly generated IDEA project in IDEA.
    3. Put your code and other things in the expected default directories as described on the sbt wiki under 'Directory Layout'. You need to create these directories yourself - sbt doesn't create them automatically. The 'src' and 'test' directories should be at the same level as the 'project' and 'target' directories that sbt created.
    4. Make up a new 'build.sbt' file and put it in ~/myCode/myProject (or whatever you called it). Since I am just figuring out sbt, mine is simple so far - just nominates scalatest as a dependency and uses Scala 2.9:

    name := "myProject"
    
    version := "0.1"
    
    organization := "me"
    
    libraryDependencies += "org.scalatest" % "scalatest_2.9.0" % "1.6.1"
    
    scalaVersion := "2.9.0"
    


  • 在IDEA屏幕底部的SBT控制台中输入 reload 命令。它应该为您下载scalatest和Scala 2.9。也许你也需要运行'更新'。

  • Enter the reload command in the SBT console at the bottom of the IDEA screen. It should download scalatest and Scala 2.9 for you. Maybe you need to run 'update' too.

    这篇关于SBT 0.10和IDEA的初学者指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆