IntelliJ Idea中Play framework/Sbt項目的配置方法

由於Play framework 2.3之後採用SBT來構建項目,而SBT使用HTTPS從Maven服務器下載各類依賴包、資源和工具,致使構建過程很是慢。解決問題的思路是修改sbt配置,讓Maven優先從阿里雲鏡像服務器中下載。瀏覽器

搭建步驟:服務器

1、在IntelliJ Idea中安裝Play 2.x和Scala插件maven

2、到Play framework官網下載Play的起始項目zip包。解壓zip文件到文件目錄假設是D:\sbt01312\,頂層目錄下有一個sbt-dist目錄,裏面包含sbt的launcher。工具

用winrar打開\bin\sbt-launch.jar文件,把裏面的\sbt\sbt.boot.properties解壓出來,而後在把[repositories]改成:ui

[repositories]
  local
  aliyun-maven: http://maven.aliyun.com/nexus/content/groups/public/
  aliyun-ivy: http://maven.aliyun.com/nexus/content/groups/public/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  sbt-plugin-ivy: http://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  dl-ivy: http://dl.bintray.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  store_mir:http://mirrors.ibiblio.org/maven2/
  store_0:http://maven.net.cn/content/groups/public/
  store_2:http://repo2.maven.org/maven2/

  maven-central: http://repo1.maven.org/maven2/
  typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
  sbt-ivy-snapshots: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly

把改好後的sbt.boot.properties放回\bin\sbt-launch.jar文件。阿里雲

3、運行IntelliJ Idea,選擇File/Other Settings/Default Settings菜單url

在Build,Execution,Deployment/Build Tools/SBT頁中,最下面的"Launcher(sbt-launch.jar)"中,選擇Custom,而後輸入框中輸入第二步修改好的\bin\sbt-launch.jar文件路徑,例如D:\sbt01312\bin\sbt-launch.jar.net

4、在IntelliJ Idea中新建一個Play 2.x項目。插件

SBT會自動構建,而且下載各類文件,須要很長時間。執行到 Loading project definition from XXXXX 的時候會卡死。是由於項目根目錄的build.sbt文件沒有從鏡像Maven中下載文件,而是從國外服務器下載。scala

此時能夠終止構建,雙擊build.sbt打開文件,而後把最後的resolvers語句改成

resolvers += "aliyun-maven" at "http://maven.aliyun.com/nexus/content/groups/public/"

resolvers += Resolver.url("aliyun-ivy", url("http://maven.aliyun.com/nexus/content/groups/public/"))( Patterns("[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]") )

resolvers += Resolver.url("sbt-plugin-ivy", url("http://dl.bintray.com/sbt/sbt-plugin-releases/"))( Patterns("[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]") )

resolvers += Resolver.url("dl-ivy", url("http://dl.bintray.com/typesafe/ivy-releases/"))( Patterns("[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]") )

注意:sbt文件兩條語句之間要各一個空行,不然出錯。

而後選擇Run/Edit Configuration菜單,新建一個運行配置,而後運行這個配置。

若是順利,項目會被從新構建,構建成功後啓動瀏覽器進入項目頁,此時配置就徹底成功了。

相關文章
相關標籤/搜索