~/.sbt/repositories 远程镜像
若没有默认访问https://repo1.maven.org/maven2
也可修改:~/.sbt/repositories
[repositories]
local ##表示本地路径~/.ivy2
my-nexus: https://127.0.0.1:8081/nexus/public/ ## 指向本地搭建的nexus 私服
aliyun: http://maven.aliyun.com/nexus/content/groups/public/ ## 指向阿里云镜像
typesafe: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sonatype-oss-releases
maven-central ## 默认maven ,maven-central 属于sbt 内置变量
sonatype-oss-snapshots
sbt 代理设置 https://www.scala-sbt.org/1.x/docs/Proxy-Repositories.html
build.sbt 依赖格式
libraryDependencies += "com.google.code.gson" % "gson" % "2.9.1"
死活不对报错,发现依赖格式错误
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.google.code.gson:gson_2.11:2.9.1
[error] Not found
[error] Not found
[error] not found: https://repo1.maven.org/maven2/com/google/code/gson/gson_2.11/2.9.1/gson_2.11-2.9.1.pom
[error] not found: https://maven.aliyun.com/repository/public/com/google/code/gson/gson_2.11/2.9.1/gson_2.11-2.9.1.pom
buildsbt %% 和% 的区别
libraryDependencies += "com.google.code.gson" %% "gson" % "2.9.1"
%%表示带上scala的version com/google/code/gson/gson_2.11/2.9.1
libraryDependencies += "com.google.code.gson" % "gson" % "2.9.1"
% 表示不带scala version com/google/code/gson/gson/2.9.1
参见 sbt 文档

完整的build.sbt
ThisBuild / version := "1.0"
ThisBuild / scalaVersion := "3.11.12"
ThisBuild / organization := "mi.com"
resolvers += DefaultMavenRepository
val spinalVersion = "1.7.2"
val spinalCore = "com.github.spinalhdl" %% "spinalhdl-core" % spinalVersion
val spinalLib = "com.github.spinalhdl" %% "spinalhdl-lib" % spinalVersion
val spinalIdslPlugin = compilerPlugin("com.github.spinalhdl" %% "spinalhdl-idsl-plugin" % spinalVersion)
lazy val mylib = (project in file("."))
.settings(
name := "misoc",
libraryDependencies ++= Seq(spinalCore, spinalLib, spinalIdslPlugin,
"org.apache.poi" % "poi" % "3.17",
"org.apache.poi" % "poi-ooxml" % "3.17"
)
)
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "3.0.0"
libraryDependencies += "com.google.code.gson" % "gson" % "2.9.1"
libraryDependencies += "com.alibaba" % "fastjson" % "1.2.76"
fork := true
本文档介绍了如何配置SBT的~/.sbt/repositories文件以使用不同的远程镜像,包括本地Nexus私服和阿里云镜像。同时,展示了在build.sbt中设置依赖的正确格式,区分了'%%'和'%'的使用。在解决依赖下载错误的过程中,提到了Scala版本对依赖路径的影响,并提供了一个完整的build.sbt示例。
9125

被折叠的 条评论
为什么被折叠?



