SBT构建开发环境与代理和仓库配置

来源:互联网 发布:广州525孕妇摄影淘宝网 编辑:程序博客网 时间:2024/05/16 13:50
SBT构建开发环境
1)安装
安装大体可参考http://www.scala-sbt.org/release/tutorial/zh-cn/Combined+Pages.html 中所示,我的过程如下:
windows环境,下载sbt-0.13.9.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
-Dsbt.log.format=true

##如下为代理的配置包括http与https.
-Dhttp.proxyHost=10.18.11.11
-Dhttp.proxyPort=8080
-Dhttp.proxyUser=xx
-Dhttp.proxyPassword=xx

-Dhttps.proxyHost=10.18.1111
-Dhttps.proxyPort=8080
-Dhttps.proxyUser=xx
-Dhttps.proxyPassword=xx

第一个是设置本地自定义repository路径(如果不设置就是默认的用户目录)。
然后在D:/sbt/conf/目录下新建repo.properties文件,内容为:
[repositories]
  local
  comp-maven:http://mvnrepository.com/artifact/
  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/
  sbt-releases-repo: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  sbt-plugins-repo: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  maven-central: http://repo1.maven.org/maven2/

请确保一定要增加高亮部分,否则会出现如下错误, 最后把路径D:\sbt\bin 添加到Path中。

D:\work\scala\sbt\bin>sbt.bat
Getting org.scala-sbt sbt 0.13.9 ...

:: problems summary ::
:::: WARNINGS
                module not found: org.scala-sbt#sbt;0.13.9
        ==== local: tried
          D:\work\scala\sbt\.ivy2\local\org.scala-sbt\sbt\0.13.9\ivys\ivy.xml
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          D:\work\scala\sbt\.ivy2\local\org.scala-sbt\sbt\0.13.9\jars\sbt.jar
        ==== comp-maven: tried
          http://mvnrepository.com/artifact/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://mvnrepository.com/artifact/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
        ==== store_cn: tried
          http://maven.oschina.net/content/groups/public/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://maven.oschina.net/content/groups/public/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
        ==== store_mir: tried
          http://mirrors.ibiblio.org/maven2/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://mirrors.ibiblio.org/maven2/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
        ==== store_0: tried
          http://maven.net.cn/content/groups/public/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://maven.net.cn/content/groups/public/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
        ==== store_1: tried
          http://repo.typesafe.com/typesafe/ivy-releases/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://repo.typesafe.com/typesafe/ivy-releases/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
        ==== store_2: tried
          http://repo2.maven.org/maven2/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.pom
          -- artifact org.scala-sbt#sbt;0.13.9!sbt.jar:
          http://repo2.maven.org/maven2/org/scala-sbt/sbt/0.13.9/sbt-0.13.9.jar
                ::::::::::::::::::::::::::::::::::::::::::::::
                ::          UNRESOLVED DEPENDENCIES         ::
                ::::::::::::::::::::::::::::::::::::::::::::::
                :: org.scala-sbt#sbt;0.13.9: not found
                ::::::::::::::::::::::::::::::::::::::::::::::

:::: ERRORS
        SERVER ERROR: Proxy Timeout ( The connection timed out. For more information about this event, see ISA Server Help.  ) url=http://repo2.maven.org/maven2/org/scala-sbt/sbt/0
.13.9/sbt-0.13.9.pom

:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.scala-sbt#sbt;0.13.9: not found
Error during sbt execution: Error retrieving required libraries
  (see D:\work\scala\sbt\.sbt\boot\update.log for complete log)
Error: Could not retrieve sbt 0.13.9

如果使用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 
https://github.com/CSUG/real_world_scala/blob/master/02_sbt.markdown 
http://blog.csdn.net/zlcd1988/article/details/21807615 spark开发搭建运行
http://blog.csdn.net/book_mmicky/article/details/25714545  spark-submit
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 解决本地库问题
1 0
原创粉丝点击