被 SBT 坑出翔

2016/10/24 Scala

最近看到学姐发专栏说有偿招 Scala ,我作为一个 JVM 厨,自然是没有不看的道理(雾)。然后我就打开了 ThoughtWorks 的那个名为 DeepDarkFantasy 的 repo♂,阅读了那充满哲♂学气息的 README.md ,然后 clone 了该 repo。

用装了 Scala 插件的 IntelliJ IDEA ,创建新 Scala -> sbt 工程,并选择工程目录为 clone 的目录。创建成功,一大片姨妈红。

我看到根目录有个 build.sbt ,看起来像是类型 build.gradle.kts 之类的依赖管理脚本,或者是啥构建工具。转念一想, sbt ,那不是 Sublime Text 吗,于是我去下了个 ST3 ,发现并不是那么回事(泣)。

然后我才知道, sbt 就是一个构建工具,全称 Simple Build Tool (我觉得称之为死变态更合适), Scala 的。本着踩坑后分享经验的精神,我就分享一下我构建学姐那个项目的生死历程吧。。

依赖

开始

首先从死变态官网下载最新的死变态(截止文章发布是 0.13.12 ,学姐仓库本身是预览版的,我给换成 Stable 了),然后把死变态的 bin 目录添加到环境变量。

然后打开 conf 目录,编辑一下 sbtconfig.txt。增加下面几行:

-Dsbt.log.format=true
-Dfile.encoding=UTF8
-Dsbt.boot.directory=D:/sbt-repo/boot/
-Dsbt.ivy.home=D:/sbt-repo/

其中的 D:/sbt-repo/和 D:/sbt-repo/boot/是我选择的 sbt 缓存目录,建议大家也改一下,改成自己看得顺眼的目录才是坠吼的,毕竟不改的话就存到用户目录下了,然后等着你的 C 盘被吃空吧。

打开命令行。

输入 sbt。然后准备好进行漫长的等待。这个过程非常漫长,我大概用了三个多小时(学校网速),请大家耐心。

Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

C:\Users\asus1>sbt
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Getting org.scala-sbt sbt 0.13.12 ...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.12/jars/sbt.jar ...
        [SUCCESSFUL ] org.scala-sbt#sbt;0.13.12!sbt.jar (8882ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main/0.13.12/jars/main.jar ...
        [SUCCESSFUL ] org.scala-sbt#main;0.13.12!main.jar (24921ms)
downloading https://repo.typesafe.com/typesae/ivy-releases/org.scala-sbt/compiler-interface/0.13.12/jars/compiler-interface.jar ...
        [SUCCESSFUL ] org.scala-sbt#compiler-interface;0.13.12!compiler-interface.jar (10973ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/actions/0.13.12/jars/actions.jar ...
        [SUCCESSFUL ] org.scala-sbt#actions;0.13.12!actions.jar (12807ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/main-settings/0.13.12/jars/main-settings.jar ...
        [SUCCESSFUL ] org.scala-sbt#main-settings;0.13.12!main-settings.jar (12497ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/interface/0.13.12/jars/interface.jar ...
        [SUCCESSFUL ] org.scala-sbt#interface;0.13.12!interface.jar (13174ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/io/0.13.12/jars/io.jar ...
        [SUCCESSFUL ] org.scala-sbt#io;0.13.12!io.jar (10630ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/ivy/0.13.12/jars/ivy.jar ...
        [SUCCESSFUL ] org.scala-sbt#ivy;0.13.12!ivy.jar (28885ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/logging/0.13.12/jars/logging.jar ...
        [SUCCESSFUL ] org.scala-sbt#logging;0.13.12!logging.jar (20714ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/logic/0.13.12/jars/logic.jar ...
        [SUCCESSFUL ] org.scala-sbt#logic;0.13.12!logic.jar (17657ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/process/0.13.12/jars/process.jar ...
        [SUCCESSFUL ] org.scala-sbt#process;0.13.12!process.jar (23467ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/run/0.13.12/jars/run.jar ...
        [SUCCESSFUL ] org.scala-sbt#run;0.13.12!run.jar (22860ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/command/0.13.12/jars/command.jar ...
        [SUCCESSFUL ] org.scala-sbt#command;0.13.12!command.jar (20673ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classpath/0.13.12/jars/classpath.jar ...
        [SUCCESSFUL ] org.scala-sbt#classpath;0.13.12!classpath.jar (11883ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/completion/0.13.12/jars/completion.jar ...
        [SUCCESSFUL ] org.scala-sbt#completion;0.13.12!completion.jar (17079ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/api/0.13.12/jars/api.jar ...
        [SUCCESSFUL ] org.scala-sbt#api;0.13.12!api.jar (22818ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-integration/0.13.12/jars/compiler-integration.jar ...
        [SUCCESSFUL ] org.scala-sbt#compiler-integration;0.13.12!compiler-integration.jar (24908ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compiler-ivy-integration/0.13.12/jars/compiler-ivy-integration.jar ...
        [SUCCESSFUL ] org.scala-sbt#compiler-ivy-integration;0.13.12!compiler-ivy-integration.jar (17102ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/relation/0.13.12/jars/relation.jar ...
        [SUCCESSFUL ] org.scala-sbt#relation;0.13.12!relation.jar (13061ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/task-system/0.13.12/jars/task-system.jar ...
        [SUCCESSFUL ] org.scala-sbt#task-system;0.13.12!task-system.jar (16287ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tasks/0.13.12/jars/tasks.jar ...
        [SUCCESSFUL ] org.scala-sbt#tasks;0.13.12!tasks.jar (9907ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/tracking/0.13.12/jars/tracking.jar ...
        [SUCCESSFUL ] org.scala-sbt#tracking;0.13.12!tracking.jar (12913ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/testing/0.13.12/jars/testing.jar ...
        [SUCCESSFUL ] org.scala-sbt#testing;0.13.12!testing.jar (16937ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/control/0.13.12/jars/control.jar ...
        [SUCCESSFUL ] org.scala-sbt#control;0.13.12!control.jar (12305ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/collections/0.13.12/jars/collections.jar ...
        [SUCCESSFUL ] org.scala-sbt#collections;0.13.12!collections.jar (12743ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/classfile/0.13.12/jars/classfile.jar ...
        [SUCCESSFUL ] org.scala-sbt#classfile;0.13.12!classfile.jar (11493ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/incremental-compiler/0.13.12/jars/incremental-compiler.jar ...
        [SUCCESSFUL ] org.scala-sbt#incremental-compiler;0.13.12!incremental-compiler.jar (11345ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/compile/0.13.12/jars/compile.jar ...
        [SUCCESSFUL ] org.scala-sbt#compile;0.13.12!compile.jar (11230ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/persist/0.13.12/jars/persist.jar ...
        [SUCCESSFUL ] org.scala-sbt#persist;0.13.12!persist.jar (10452ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/cross/0.13.12/jars/cross.jar ...
        [SUCCESSFUL ] org.scala-sbt#cross;0.13.12!cross.jar (10256ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/ivy/ivy/2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a/ivy-2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a.jar ...
        [SUCCESSFUL ] org.scala-sbt.ivy#ivy;2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a!ivy.jar (51299ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/cache/0.13.12/jars/cache.jar ...
        [SUCCESSFUL ] org.scala-sbt#cache;0.13.12!cache.jar (12691ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/test-agent/0.13.12/jars/test-agent.jar ...
        [SUCCESSFUL ] org.scala-sbt#test-agent;0.13.12!test-agent.jar (8653ms)
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/apply-macro/0.13.12/jars/apply-macro.jar ...
        [SUCCESSFUL ] org.scala-sbt#apply-macro;0.13.12!apply-macro.jar (10817ms)
:: retrieving :: org.scala-sbt#boot-app
        confs: [default]
        49 artifacts copied, 0 already retrieved (17462kB/1761ms)
Getting Scala 2.10.6 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
        confs: [default]
        5 artifacts copied, 0 already retrieved (24494kB/726ms)
[info] Set current project to asus1 (in build file:/C:/Users/asus1/)
>

这是我顺利下载全部 jar 的样子。供来者参考。

然后我打开了 IntelliJ IDEA ,准备愉快地开始 Code Review 时,我发现 IntelliJ IDEA 又开始下载,下载第二遍。。。

[掀桌 (╯‵□′)╯︵┻━┻]

打开设置,找到Build, Execution, Deployment下的 Build Tools 中的 SBT ,我目测把 Launcher 改成自己的那个 Launcher (就是安装目录下的 bin/sbt-launch.jar )就没问题了。估计是在创建新工程的过程中, IDEA 使用了自带的 SBT ,导致我的三小时辛苦下载没有什么卵用。

顺便把上面的 Javadoc 也勾上吧,免得坑死人不偿命。再勾上 source ,一不做二不休,我已经准备好通宵下载了。

然后 Close Project 再 Open Project ,看到它开始刷新了。我借了同学的 VPN (中国好同学),又经历了两个小时,搞定了。。。

我编译了一下那份时不时报错的代码,一分钟过后编译成功。好一个 Scalac ,编译真快,嗯。

有啥不清楚的邮件联系我啊,我补上。


Search

    Post Directory



    如果觉得这篇文章给您带来了收获或者说它值得您这么做,您可以选择对我进行捐助。
    下面是微信支付哟