如何快速下载sbt的依赖

  最近因为工作需要用到了scala项目,scala项目有自己的构建工具sbt,而sbt在构建的时候默认会从repo1.maven.org下载依赖,由于我天朝的特殊性所以要么是大家用不了,要么就是下载速度会非常慢。本人也碰到了这个问题从网上找的方法但都不行。最后终于从官网上看到相应的描述,如下

  简单的说如果你想添加远程仓库可以使用resolvers配置,如果你想修改或删除默认的远程仓库则要覆盖externalResolvers。而下载依赖都是使用默认的远程仓库,所以我们要覆盖externalResolvers。具体操作:找到工程下面的build.sbt文件,打开它添加如下配置

// 将阿里云仓库做为默认仓库
externalResolvers := List("my repositories" at "https://maven.aliyun.com/nexus/content/groups/public/")

 // 将阿里云仓库做为默认仓库
externalResolvers := List("my repositories" at "https://maven.aliyun.com/nexus/content/groups/public/"),

  改完后的配置如下

resolvers += Resolver.mavenLocal
resolvers += Resolver.bintrayRepo("hseeberger", "maven")
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
// 将阿里云仓库做为默认仓库
externalResolvers := List("my repositories" at "https://maven.aliyun.com/nexus/content/groups/public/")

lazy val commonSettings = Seq(
  organization := "com.actionml",
  scalaVersion := "2.11.12",
  updateOptions := updateOptions.value.withLatestSnapshots(false),
  resolvers += Resolver.bintrayRepo("hseeberger", "maven"),
  resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
  resolvers += Resolver.mavenLocal,
  // 将阿里云仓库做为默认仓库
  externalResolvers := List("my repositories" at "https://maven.aliyun.com/nexus/content/groups/public/"),
  libraryDependencies ++= Seq(
    "org.apache.hadoop" % "hadoop-hdfs" % hdfsVersion,
    "org.apache.hadoop" % "hadoop-common" % hdfsVersion,
    "ch.qos.logback" % "logback-classic" % "1.2.3",
    "com.typesafe.scala-logging" %% "scala-logging" % "3.5.0",
    "org.typelevel" %% "cats" % "0.9.0",
    "com.typesafe" % "config" % "1.3.1",
    "com.iheart" %% "ficus" % "1.4.0",
    "org.scalatest" %% "scalatest" % scalaTestVersion % "test"
  ),
  excludeDependencies ++= Seq(
    SbtExclusionRule("org.slf4j", "log4j-over-slf4j"),
    SbtExclusionRule("org.slf4j", "slf4j-log4j12")
  )
)

  改完配置保存下就可以使用了,亲测下载速度飞起~

推荐阅读更多精彩内容