sbt随笔161019

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插件,如下图:

然后在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.html 
http://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 解决本地库问题
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值