转载

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

因为Play framework 2.3以后采用SBT来构建项目,而SBT使用HTTPS从Maven服务器下载各种依赖包、资源和工具,导致构建过程非常慢。解决问题的思路是修改sbt配置,让Maven优先从阿里云镜像服务器中下载。

搭建步骤:

一、在IntelliJ Idea中安装Play 2.x和Scala插件

二、到Play framework官网下载Play的起始项目zip包。解压zip文件到文件目录假设是 D:/sbt01312/ ,顶层目录下有一个sbt-dist目录,里面包含sbt的launcher。

用winrar打开 /bin/sbt-launch.jar 文件,把里面的 /sbt/sbt.boot.properties 解压出来,然后在把[repositories]改为:

[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 文件。

三、运行IntelliJ Idea,选择 File/Other Settings/Default Settings 菜单

在Build,Execution,Deployment/Build Tools/SBT页中,最下面的"Launcher(sbt-launch.jar)"中,选择Custom,然后输入框中输入第二步修改好的 /bin/sbt-launch.jar 文件路径,例如 D:/sbt01312/bin/sbt-launch.jar

四、在IntelliJ Idea中新建一个Play 2.x项目。

SBT会自动构建,并且下载各种文件,需要很长时间。执行到 Loading project definition from XXXXX 的时候会卡死。是因为项目根目录的build.sbt文件没有从镜像Maven中下载文件,而是从国外服务器下载。

此时可以终止构建,双击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菜单,新建一个运行配置,然后运行这个配置。

如果顺利,项目会被重新构建,构建成功后启动浏览器进入项目页,此时配置就完全成功了。

原文  https://segmentfault.com/a/1190000018555222
正文到此结束
Loading...