SBT构建开发环境
1)安装
安装大体可参考
http://www.scala-sbt.org/release/tutorial/zh-cn/Combined+Pages.html 中所示,我的过程如下:
windows环境,下载sbt-0.13.6.zip,解压后到D:/sbt/(不要有空格的路径),然后修改D:/sbt/conf目录下的sbtconfig.txt文件,在最后加入如下几行配置:
-Dsbt.ivy.home=D:/sbt/.ivy2
-Dsbt.global.base=D:/sbt/.sbt
-Dsbt.repository.config=D:/sbt/conf/repo.properties
第一个是设置本地自定义repository路径(如果不设置就是默认的用户目录)。
然后在D:/sbt/conf/目录下新建repo.properties文件,内容为:
[repositories]
local
comp-maven: http://repo.data.1verge.net/nexus/content/groups/public/
store_cn: http://maven.oschina.net/content/groups/public/
store_mir: http://mirrors.ibiblio.org/maven2/
store_0: http://maven.net.cn/content/groups/public/
store_1: http://repo.typesafe.com/typesafe/ivy-releases/
store_2: http://repo2.maven.org/maven2/
最后把 路径 D:\sbt\bin 添加到Path中。
如果使用Idea来开发有关scala sbt项目,那需要在idea里安装scala插件,如下图:
![](https://img-blog.csdn.net/20150717122934378?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
然后在settings里更改两个地方:
![](https://img-blog.csdn.net/20150717123035559?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
第一个是sbt_launch.jar的本地路径。
第二个是VM parameters的设置,加入最后两行就可使用本地ivy库。
-Dsbt.ivy.home=D:/sbt/.ivy2
-Dsbt.global.base=D:/sbt/.sbt
-Dsbt.repository.config=D:/sbt/conf/repo.properties
第一个是设置本地自定义repository路径(如果不设置就是默认的用户目录)。
然后在D:/sbt/conf/目录下新建repo.properties文件,内容为:
[repositories]
local
comp-maven: http://repo.data.1verge.net/nexus/content/groups/public/
store_cn: http://maven.oschina.net/content/groups/public/
store_mir: http://mirrors.ibiblio.org/maven2/
store_0: http://maven.net.cn/content/groups/public/
store_1: http://repo.typesafe.com/typesafe/ivy-releases/
store_2: http://repo2.maven.org/maven2/
最后把 路径 D:\sbt\bin 添加到Path中。
如果使用Idea来开发有关scala sbt项目,那需要在idea里安装scala插件,如下图:
然后在settings里更改两个地方:
第一个是sbt_launch.jar的本地路径。
第二个是VM parameters的设置,加入最后两行就可使用本地ivy库。
这样就完成了sbt与idea scala插件的安装,以后用idea建sbt工程都会用那个本地库。
3)在cmd中,进入项目路径中后,键入sbt,然后就可使用命令(compile,package)就可以将依赖包加到库中,编译,测试,打包等。
4)有关libraryDependencies,格式为:
groupID % artifactID % revision,或者
groupID %% artifactID % revision,使用后者的话,
artifactID将会加上当前scala版本对应的jar的version号,我认为这种方式很容易造成错误。
If you use groupID %% artifactID % revision rather than groupID % artifactID % revision (the difference is the double %% after the groupID), sbt will add your project’s Scala version to the artifact name. This is just a shortcut. You could write this without the %%:
libraryDependencies += "org.scala-tools" % "scala-stm_2.11.1" % "0.3"
Assuming the scalaVersion for your build is 2.11.1, the following is identical (note the double %% after "org.scala-tools"):
libraryDependencies += "org.scala-tools" %% "scala-stm" % "0.3"
相关参考:http://www.scala-sbt.org/release/tutorial/zh-cn/Combined+Pages.htmlhttp://my.oschina.net/u/580483/blog/110499 修改sbt默认缓存路径http://www.cnblogs.com/vincent-hv/p/3298416.html 本地编写并运行scala程序http://www.scala-sbt.org/0.13/tutorial/Library-Dependencies.html sbt官方 http://stackoverflow.com/questions/23845357/changing-ivy-cache-location-for-sbt-projects-in-intellij-idea 解决本地库问题