Freewind @ Thoughtworks scala java javascript dart 工具 编程实践 月结 math python english [comments admin] [feed]

(2014-09-12) 基本的build.sbt配置

广告: 云梯:翻墙vpn (省10元) 土行孙:科研用户翻墙http proxy (有优惠)

有时候我们想快速执行一些scala代码,但是它又依赖第三方的库,这时可以使用下面的sbt配置来快速执行:

build.sbt

name := "hello"

version := "1.0"

organization := "org.my"

scalaVersion := "2.11.0"

sbtVersion := "0.13.5"

resolvers ++= Seq(
  "ibiblio" at "http://mirrors.ibiblio.org/pub/mirrors/maven2",
  "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
  "Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases",
  "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases"
)

libraryDependencies ++= Seq(
  "org.apache.commons" % "commons-lang3" % "3.3.2",
  "commons-io" % "commons-io" % "2.4",
  "com.google.guava" % "guava" % "18.0",
  "org.scalaz" %% "scalaz-core" % "7.1.0",
  "io.argonaut" %% "argonaut" % "6.1-M4",
  "net.databinder" %% "unfiltered" % "0.8.1",
  "net.databinder" %% "unfiltered-filter-async" % "0.8.1",
  "net.databinder" %% "unfiltered-jetty" % "0.8.1",
  "ch.qos.logback" % "logback-classic" % "1.1.2",
  "org.slf4j" % "slf4j-api" % "1.7.7",
  "org.commonjava.googlecode.markdown4j" % "markdown4j" % "2.2-cj-1.0",
  "com.github.spullara.mustache.java" % "compiler" %    "0.8.16",
  "org.jsoup" % "jsoup" % "1.7.3",
  "org.specs2" %% "specs2" % "2.4.2" % "test"
)

libraryDependencies里加的东西比较多,可以自行删减或增加。

然后运行:

$ sbt
> update

将会下载各依赖。

生成idea项目

在项目目录下创建project/plugins.sbt文件,内容如下:

resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

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

然后执行:

$ sbt
> gen-idea sbt-classifiers

将会生成idea所需的配置文件,可以直接使用idea打开。

其中参数sbt-classifiers是指同时下载源代码和文档,如果不需要可以去掉。它还有很多参数可使用。

如果觉得每次都设置idea插件很麻烦,可以把它设为全局的,参看: TODO Add link

comments powered by Disqus