SBT構建開發環境與代理和倉庫配置
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.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
-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
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
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 解決本地庫問題
相關文章
- vue-cli開發環境代理配置Vue開發環境
- 構建Java Web開發環境JavaWeb開發環境
- spark開發環境搭建intellij+Scala+sbtSpark開發環境IntelliJ
- 用 Docker 構建 PHP 開發環境DockerPHP開發環境
- XamarinForms教程構建XamarinForms開發環境ORM開發環境
- 2-2 Scala專案構建工具sbt和IntelliJ IDEA環境配置IntelliJIdea
- 基於 Vagrant 構建 PHP 開發環境PHP開發環境
- Docker 構建 Java Web 開發環境(一)DockerJavaWeb開發環境
- linux下CUDA開發環境構建Linux開發環境
- 開發環境配置開發環境
- 安裝與配置Flutter開發環境Flutter開發環境
- emacs開發環境配置(4)——rust開發環境Mac開發環境Rust
- 配置開發環境、生成環境、測試環境開發環境
- 如何構建基於 docker 的開發環境Docker開發環境
- Docker 構建統一的前端開發環境Docker前端開發環境
- 如何構建基於docker的開發環境Docker開發環境
- react 配置開發環境React開發環境
- js開發環境配置JS開發環境
- Java開發環境配置Java開發環境
- weex開發環境配置開發環境
- Arduino開發環境配置UI開發環境
- 重構之路:webpack區分生產環境和開發環境Web開發環境
- GoLand編譯器配置代理和專案環境配置GoLand編譯
- Java開發環境的安裝和配置Java開發環境
- Nuxt.js中配置生產環境和開發環境APIUXJS開發環境API
- 徒手用 Docker 構建自己的 PHP 開發環境DockerPHP開發環境
- 基於 Docker 構建統一的開發環境Docker開發環境
- 構建一個基於容器的開發環境開發環境
- 用Vagrant構建統一的golang開發環境Golang開發環境
- 構建你的Office 365開發環境 - IOS版開發環境iOS
- 構建你的Office 365開發環境 - 其他版本開發環境
- Docker 構建 Java Web 開發環境——使用Dockerfile(二)DockerJavaWeb開發環境
- Windows 下使用 Vagrant 構建 Linux 開發環境WindowsLinux開發環境
- 配置軟體原始碼包構建環境原始碼
- Docker配置PHP開發環境DockerPHP開發環境
- MacOS 配置 Flutter 開發環境MacFlutter開發環境
- MacOS PHP 開發環境配置MacPHP開發環境
- (二) electron 開發環境配置開發環境