如何通过SSL设置插件下载?

时间:2014-09-08 11:29:13

标签: sbt

我有一个使用sbt-start-script插件的SBT项目。当我运行SBT时,插件jar是通过不安全的HTTP而不是HTTPS下载的:

  

下载http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-start-script/scala_2.10/sbt_0.13/0.10.0/jars/sbt-start-script.jar ...

我想使用repo的https版本(我可以手动浏览),但我无法弄清楚如何让SBT使用它。

我的project/plugins.sbt看起来像这样:

addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0")

我尝试将https版本添加到SBT属性' [repositories]部分,并尝试将其添加到resolvers列表,但SBT始终使用回购的http版本。

addSbtPlugin会自动添加回购吗?

1 个答案:

答案 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

Command Line Options说:

  • ➜ 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