32

sbt下载加速方案

 5 years ago
source link: http://www.zhyea.com/2018/11/30/sbt-accelerate.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本来不太想使用sbt,但是公司这边普遍要求使用sbt来进行部署。所以,so!

sbt的语法什么的还好,唯一让人无法忍受的是sbt下载依赖的速度 —— 在国内大环境下实在是慢到了让人抓狂的程度。

要提升sbt下载依赖的速度,方法无非是那么几个:土豪可以考虑使用VPN,不想花钱可以考虑替换repository。

下面贴一下我用的repositories,并简单说明下。

[repositories]
	local
	sonatype-nexus-repository: https://maven.company.com/nexus/content/groups/public/
	maven-local: file:///D:/maven/mvnrepo
	repox-maven: http://repox.gtan.com:8078/
	repox-ivy: http://repox.gtan.com:8078/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
	osc: http://maven.aliyun.com/nexus/content/groups/public/
	typesafe:http://dl.bintray.com/typesafe/ivy-releases/ , [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
	ivy-sbt-plugin:http://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

第一行的local意思是使用本地源,不过好像没有什么大用。

第二行用的是公司的私有maven源。

第三行使用的是maven本机仓库,确定需要指明下仓库的位置才能生效。

第四行和第五行用的是社区公服。社区公服是一个公益项目,详情可以看下 这里 。社区公服原名广谈公服,主要能力就是解决sbt下载依赖太慢的问题。事实证明,社区公服真的是一个好东西,用上了以后,sbt下载依赖的速度当真飞快。

第六行是阿里云的依赖仓库,不过因为广谈公服排在前面,少见它能发挥作用。

第七行和第八行的仓库主要是解决typesafe相关源下载太慢或者下载失败的问题。即使用上了社区公服和阿里云maven仓库,一些typesafe出的sbt插件下载速度仍是巨慢。当时因为这个被绊住了好久。使用dl.bintray.com的源能很好地解决这个问题。据说typesafe的下载源也是指向这里,至于为什么typesafe源下载慢dl.bintray.com下载快就不清楚了。

有这几个源差不多就够了,添加的源如果太多,遇到一些特别“稀有”的依赖,sbt会串行地尝试每个源,如果每个源都失败,耗费的时间加在一起也很恐怖了。

————————————————————————————

现在又调整了一下repositories,主要添加了几个maven仓库的ivy布局兼容:

[repositories]
	local
	maven-local: file:///D:/JDevelop/mvnrepo
	td-maven: https://maven.zhyea.com/nexus/content/groups/public/
	td-ivy: https://maven.zhyea.com/nexus/content/groups/public/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
	repox-maven: http://repox.gtan.com:8078/
	repox-ivy: http://repox.gtan.com:8078/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
	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]
	typesafe: http://dl.bintray.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
	ivy-sbt-plugin:http://dl.bintray.com/sbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
	jcenter: http://jcenter.bintray.com/
	jcenter-ivy: http://jcenter.bintray.com/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
	sonatype-oss-releases
	maven-central
	sonatype-oss-snapshots

扯一些没用的。

编译工具我有用过maven、gradle和sbt三种。从私心上来说比较喜欢gradle的简洁特征的,sbt稍微有些复杂了,不过也比maven好一些。在IDE的支持上,maven因为用户基数大,得到的支持是最好的,gradle有安卓开发者加持也还不错,比较起来sbt是最差的:在idea上使用sbt经常出现依赖下载不了,索引失效等问题。所以在我看来,在国内进行scala开发最好选择gradle,其次选择maven,至于sbt——人生短暂,干嘛不做一些更有意义的事情呢。

关于sbt的的不足,这里有一篇文章 《So, what’s wrong with SBT?》 说了些干货,有兴趣可以看看,不过我是不太能完全理解的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK