在 sbt 中通过 https 访问 maven repo

agy*_*eya 9 java scala maven sbt

我有一个使用 sbt(scala) 进行构建的 java 项目。直到昨天,这仍然有效,但今天我看到从 Maven 中提取回购的问题

esolving org.codehaus.plexus#plexus-component-api;1.0-alpha-16 ...

[error] SERVER ERROR: HTTPS Required url=http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom

[warn]  module not found: org.codehaus.plexus#plexus-component-api;1.0-alpha-16

[warn] ==== typesafe-ivy-releases: tried

[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.codehaus.plexus/plexus-component-api/1.0-alpha-16/ivys/ivy.xml

[warn] ==== sbt-plugin-releases: tried

[warn]   http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.codehaus.plexus/plexus-component-api/1.0-alpha-16/ivys/ivy.xml

[warn] ==== local: tried

[warn]   /root/.ivy2/local/org.codehaus.plexus/plexus-component-api/1.0-alpha-16/ivys/ivy.xml

[warn] ==== activator-local: tried

[warn]   file:/heimdall/app/projects/load-test/content-engine/repository/org.codehaus.plexus/plexus-component-api/1.0-alpha-16/ivys/ivy.xml

[warn] ==== public: tried

[warn]   http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom

[warn] ==== typesafe-releases: tried

[warn]   http://repo.typesafe.com/typesafe/releases/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom

[warn] ==== typesafe-ivy-releasez: tried

[warn]   http://repo.typesafe.com/typesafe/ivy-releases/org.codehaus.plexus/plexus-component-api/1.0-alpha-16/ivys/ivy.xml

[warn] ==== Typesafe repository: tried

[warn]   http://repo.typesafe.com/typesafe/releases/org/codehaus/plexus/plexus-component-api/1.0-alpha-16/plexus-component-api-1.0-alpha-16.pom
Run Code Online (Sandbox Code Playgroud)

根据我的推断,repo 似乎已移至 https 端点。并且 pom 文件在 https 端点上可用。问题是这不是我项目中的直接依赖项,而是通过其他一些依赖项传递过来的。如何将 https 用于此特定依赖项?

我正在使用 sbt 版本 0.13.5。我检查了它的参考手册,并在 build.sbt 中明确添加了DefaultMavenRepository

resolvers += DefaultMavenRepository
Run Code Online (Sandbox Code Playgroud)

根据此官方文档, DefaultMavenRepository 指向安全端点。在此之前,我曾在 build.sbt 中尝试过以下内容

resolvers += "Maven Repo" at  "https://repo1.maven.org/maven2/" 
Run Code Online (Sandbox Code Playgroud)

并添加

"org.codehaus.plexus" % "plexus-component-api" % "1.0-alpha-16", 
Run Code Online (Sandbox Code Playgroud)

在我的 build.sbt 中明确作为 libraryDepdency 以便它可以被缓存并且不会传递到我可能无法控制它从哪里被拉出的地方。但这也失败了。我清除了 m2 和 ivy2 缓存

小智 9

创建一个 sbt 配置文件~/.sbt/repositories并添加以下配置:

[repositories] 
maven-central: https://repo1.maven.org/maven2
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到更多信息 - https://www.scala-sbt.org/1.x/docs/Proxy-Repositories.html


小智 8

检查 sbt 配置文件中的链接:~/.sbt/repositories

将行更改 maven-central: http://repo1.maven.org/maven2/maven-central: https://repo1.maven.org/maven2/

它修复了没有 sbt 更新的下载


agy*_*eya 5

正如 Sarvesh 所提到的,问题是我使用的是 sbt 版本 0.13.5。并且 DefaultMavenRepository 从 v0.13.6 开始指向 https 端点(文档没有提到这一点)。提升版本后,我能够拉取所有依赖项。