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

6次阅读

共计 2735 个字符,预计需要花费 7 分钟才能阅读完成。

因为 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 菜单,新建一个运行配置,然后运行这个配置。
如果顺利,项目会被重新构建,构建成功后启动浏览器进入项目页,此时配置就完全成功了。

正文完
 0