我有一个使用sbt-start-script插件的SBT项目。当我运行SBT时,插件jar是通过不安全的HTTP而不是HTTPS下载的:
我想使用repo的https
版本(我可以手动浏览),但我无法弄清楚如何让SBT使用它。
我的project/plugins.sbt
看起来像这样:
addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0")
我尝试将https
版本添加到SBT属性' [repositories]
部分,并尝试将其添加到resolvers
列表,但SBT始终使用回购的http
版本。
addSbtPlugin
会自动添加回购吗?
答案 0 :(得分:2)
tl; dr 使用https版本创建~/.sbt/repositories
或创建具有不同非默认名称的存储库文件,并使用sbt
和{{运行-Dsbt.override.build.repos=true
1}}。
让我们从默认的构建定义开始 - 没有额外的设置,但sbt本身带来了什么。
-Dsbt.repository.config=path-to-the-repositories-file
知道自动托管依赖项的外部解析器 - 有三个解析器(格式化是为了方便阅读)。
show fullResolvers
➜ https-repositories xsbt
...
> show fullResolvers
[info] ArrayBuffer(
Raw(ProjectResolver(inter-project, mapped: )),
FileRepository(local,FileConfiguration(true,None),Patterns(ivyPatterns=List(${ivy.home}/local/[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(${ivy.home}/local/[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)),
public: https://repo1.maven.org/maven2/)
如果sbt.override.build.repos
,则忽略构建定义中配置的存储库,而是使用为启动器配置的存储库。请参阅true
和sbt启动器文档。sbt.repository.config
包含用于启动程序的存储库的文件。格式与sbt启动器配置文件的sbt.repository.config
部分相同。此设置通常与将[repositories]
设置为true一起使用(请参阅上一行和sbt启动器文档)。这意味着当sbt在sbt.override.build.repos
内找到~/.sbt/repositories
时,他们将成为sbt的解析器。
使用以下内容创建[repositories]
:
~/.sbt/repositories
您可能已经注意到, 文件定义了相关存储库的https版本。
[repositories]
httpsInstead: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/,[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
会话(或重新开始)并执行reload
。
show fullResolvers
现在有两个解析器!
让我们使用➜ https-repositories ls ~/.sbt/repositories
/Users/jacek/.sbt/repositories
➜ https-repositories xsbt
...
> show fullResolvers
[info] ArrayBuffer(
Raw(ProjectResolver(inter-project, mapped: )),
URLRepository(httpsInstead,Patterns(ivyPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)))
选项 - sbt.*
和sbt.override.build.repos
。
sbt.repository.config
再次有两个解析器。
➜ https-repositories ls ~/.sbt/my_repositories
/Users/jacek/.sbt/my_repositories
➜ https-repositories ls ~/.sbt/repositories*
zsh: no matches found: /Users/jacek/.sbt/repositories*
➜ https-repositories SBT_OPTS="-Dsbt.override.build.repos=false -Dsbt.repository.config=/Users/jacek/.sbt/my_repositories" xsbt
...
> show fullResolvers
[info] ArrayBuffer(
Raw(ProjectResolver(inter-project, mapped: )),
URLRepository(httpsInstead,Patterns(ivyPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)))
似乎没有太大变化。
sbt.override.build.repos=true
有趣的是,对于➜ https-repositories SBT_OPTS="-Dsbt.override.build.repos=true -Dsbt.repository.config=/Users/jacek/.sbt/my_repositories" xsbt
...
> show fullResolvers
[info] ArrayBuffer(
Raw(ProjectResolver(inter-project, mapped: )),
URLRepository(httpsInstead,Patterns(ivyPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)))
,解析器会针对sbt项目构建进行更改。
这是一个带有虚构存储库的示例sbt.override.build.repos=true
:
build.sbt
第一个会话是resolvers += "build.sbt" at "http://my.repository.com"
:
-Dsbt.override.build.repos=false
➜ https-repositories SBT_OPTS="-Dsbt.override.build.repos=false -Dsbt.repository.config=/Users/jacek/.sbt/my_repositories" xsbt
...
> show fullResolvers
[info] ArrayBuffer(
Raw(ProjectResolver(inter-project, mapped: )),
URLRepository(httpsInstead,Patterns(ivyPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/[organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)),
build.sbt: http://my.repository.com)
的另一个会话:
-Dsbt.override.build.repos=true