sbt 0.11:使用企业 Maven 存储库

编程入门 行业动态 更新时间:2024-10-25 20:31:02
本文介绍了sbt 0.11:使用企业 Maven 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如 如何让 sbt 使用本地 maven 代理存储库 (Nexus)? ?在 github 的新 sbt wiki 中没有提到 ivyRepositories,所以我假设接受的解决方案已经过时了.

How can a corporate Maven repository be used (to the exclusion of other repositories) with sbt 0.11.x, as described in how do I get sbt to use a local maven proxy repository (Nexus)? ? There is no mention of ivyRepositories in the new sbt wiki at github, so I'm assuming the accepted solution there is out of date.

推荐答案

第 1 步:按照 Detailed Topics: Proxy Repositories,我总结并添加到下面:

Step 1: Follow the instructions at Detailed Topics: Proxy Repositories, which I have summarised and added to below:

  • (如果您使用 Artifactory,则可以跳过此步骤.)在您的公司 Maven 存储库上创建一个完全独立的 Maven 代理存储库(或组),以代理 ivy-style 存储库,例如这两个重要的存储库:

  • (If you are using Artifactory, you can skip this step.) Create an entirely separate Maven proxy repository (or group) on your corporate Maven repository, to proxy ivy-style repositories such as these two important ones:

    • repo.typesafe/typesafe/ivy-releases/
    • repo.scala-sbt/scalasbt/sbt-plugin-releases/

    这是必需的,因为一些存储库管理器无法处理混合在一起的 Ivy 风格和 Maven 风格的存储库.

    This is needed because some repository managers cannot handle Ivy-style and Maven-style repositories being mixed together.

    创建一个文件 repositories,列出您的主要公司存储库和您在第 1 步中创建的任何其他存储库,格式如下:

    Create a file repositories, listing both your main corporate repository and any extra one that you created in step 1, in the format shown below:

    [repositories] my-maven-proxy-releases: repo.example/maven-releases/ my-ivy-proxy-releases: repo.example/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  • 要么将该文件保存在主目录内的 .sbt 目录中,要么在 sbt 命令行中指定它(如果有 禁用共享):

  • Either save that file in the .sbt directory inside your home directory, or specify it on the sbt command line (you will need to specify if you have disabled sharing):

    sbt -Dsbt.repository.config=<path-to-your-repo-file>

  • 对于那些使用旧版本 sbt 的人来说是个好消息:尽管至少在 sbt 0.12.0 启动器 jar 中,旧 sbt 版本的启动属性文件不包含所需的行 (提到 repository.config 的那个),如果您编辑这些文件以添加所需的行并将它们重新打包到 sbt 0.12.0 启动器 jar 中,它仍然适用于那些版本的 sbt!这是因为该功能是在启动器中实现的,而不是在 sbt 本身中实现的.并且 sbt 0.12.0 启动器声称能够启动所有版本的 sbt,直接回到 0.7!

    Good news for those using older versions of sbt: Even though, in the sbt 0.12.0 launcher jar at least, the boot properties files for older sbt versions don't contain the required line (the one that mentions repository.config), it will still work for those versions of sbt if you edit those files to add the required line, and repackage them into the sbt 0.12.0 launcher jar! This is because the feature is implemented in the launcher, not in sbt itself. And the sbt 0.12.0 launcher is claimed to be able to launch all versions of sbt, right back to 0.7!

    第 2 步:为确保未使用外部存储库,请从解析器中删除默认存储库.这可以通过以下三种方式之一完成:

    Step 2: To make sure external repositories are not being used, remove the default repositories from your resolvers. This can be done in one of three ways:

  • 添加上面详细主题页面中提到的命令行选项-Dsbt.override.build.repos=true.这将导致您在文件中指定的存储库覆盖在任何 sbt 文件中指定的任何存储库.不过,这可能仅适用于 sbt 0.12 及更高版本 - 我还没有尝试过.
  • 效果和1一样,可以使用overrideBuildResolvers := true,好处是可以控制适用的项目,具体取决于哪个范围(一个项目/ThisBuild/Global) 你在其中定义它.这适用于 sbt 0.13.
  • 在您的构建文件中使用 fullResolvers := Seq( resolver(s) for your company maven repositories ),而不是 resolvers ++= 或 resolvers := 或任何你曾经使用过的东西.
  • Add the command line option -Dsbt.override.build.repos=true mentioned on the Detailed Topics page above. This will cause the repositories you specified in the file to override any repositories specified in any of your sbt files. This might only work in sbt 0.12 and above, though - I haven't tried it yet.
  • Having the same effect as 1, you can use overrideBuildResolvers := true, with the advantage that you can control the projects where it is applicable, depending on which scope (a project / ThisBuild / Global) you define it in. This works in sbt 0.13.
  • Use fullResolvers := Seq( resolver(s) for your corporate maven repositories ) in your build files, instead of resolvers ++= or resolvers := or whatever you used to use.
  • 最后,请注意 sbt 启动器脚本在读取 sbtopts 文件时存在错误,因此如果您决定将常用的 sbt 命令行选项放在那里,请确保文件以换行符结尾(特别是 Emacs 可能无法确保这一点,除非配置为这样做).

    Finally, note that the sbt launcher script has a bug in reading the sbtopts file, so if you decide to put your common sbt command-line options in there, make sure the last line of the file ends in a newline (Emacs in particular can fail to ensure this, unless configured to do so).

    更多推荐

    sbt 0.11:使用企业 Maven 存储库

    本文发布于:2023-07-24 13:19:36,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1203684.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:企业   sbt   Maven

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!