Scala 为什么sbt不选择范围内最新的依赖项版本?
在build.sbt中,我们可以为依赖项声明一个范围;例如:Scala 为什么sbt不选择范围内最新的依赖项版本?,scala,sbt,Scala,Sbt,在build.sbt中,我们可以为依赖项声明一个范围;例如: libraryDependencies += groupID %% "mylib" % "[2.0,)" 在我的例子中,有多个包属于这个范围(我的存储库中有2.0.2、2.0.3、2.0.4甚至一些更奇特的版本,如mylib的2.0.1.dev和2.0.3-dev) 当我尝试构建这个项目时,sbt因此毫无理由地选择了2.0.2版。我希望他能拿到这个范围内最大的数字,但他从来没有。以下是我尝试过的需求和他选择的版本(因此,只有在指定确
libraryDependencies += groupID %% "mylib" % "[2.0,)"
在我的例子中,有多个包属于这个范围(我的存储库中有2.0.2、2.0.3、2.0.4甚至一些更奇特的版本,如mylib的2.0.1.dev和2.0.3-dev)
当我尝试构建这个项目时,sbt
因此毫无理由地选择了2.0.2版。我希望他能拿到这个范围内最大的数字,但他从来没有。以下是我尝试过的需求和他选择的版本(因此,只有在指定确切的版本号时,他才会选择更新的版本):
我已经尝试了以下解决方法:
- 删除本地~/.sbt和~/.ivy2目录
- 运行
以避免任何缓存效果sbt-no share-sbt dir/tmp/sbt-ivy dir/tmp/ivy
- 在我的主目录中搜索名称中包含mylib的任何文件;仅找到ind~/.ivy2
- 我用sbt 0.13.16运行了大多数测试,但我用0.13.15和0.13.17进行了尝试
- 请注意,我的所有构建每次都在git存储库的干净克隆中运行;因此,没有目标目录保留
- mylib的2.0.2、2.0.3和2.0.4版本包含相同的代码和依赖项(为了测试目的,我重新发布了它们)
- 问题(仅此一次)似乎并不存在于
sbt
中
我尝试了SBT1.2.1和range2.1.x
。现在sbt抱怨他找不到这种依赖性;他列出了可用的版本:
[warn] ==== my-maven-repo: tried
[warn] http://my-server/nexus/repository/my-repo/eu/company/mylib_2.12/[revision]/mylib_2.12-[revision].pom
[warn] [2.0.2, 2.0.2-dev.20180719.16.55.39.develop.dc3a706, 2.0.1-dev.20180719.16.49.57.develop.dc3a706, 2.0.1-dev.20180719.16.42.31.develop.dc3a706, 2.0.1.dev.20180719.16.31.59.develop.dc3a706]
奇怪的是,他没有列出我的NexusMaven存储库中所有可用的软件包。
使用nexus接口删除一个包后;这张单子似乎已经完成了
因此真正的问题似乎是sbt publish
到nexus存储库不会在该存储库中重新创建索引
变通办法
我已经创建了一个自定义的sbt发布包装器脚本,以强制nexus
在发布新库时重新创建存储库元数据:
#!/bin/bash
set -e
# just run sbt publish with the passed arguments as-is
sbt $@ publish
# now make sure the repository on nexus is re-indexed
# this triggers a task to recreate metadata for all maven repositories. This task was manually configured in nexus.
# the id was obtained running `curl -v -u admin:***** -X GET http://my-company/nexus/service/rest/v1/tasks`
# the recreate-maven-repos needs only the nx-tasks-run privilege
curl -q -u recreate-maven-repos:recreate -X POST http://my-company/nexus/service/rest/v1/tasks/c42ab5f5-4bd6-4ed3-b2f1-d061c24a9b90/run
我看到很多人都遇到过这个问题,但是有没有人提出了一个简单的解决方案,我可以把它放在我的publishTo目标中,只需重新创建元数据xml文件?@CarlZmola。从那时起,我实施了一个变通办法。我在回答中增加了这一变通办法。
#!/bin/bash
set -e
# just run sbt publish with the passed arguments as-is
sbt $@ publish
# now make sure the repository on nexus is re-indexed
# this triggers a task to recreate metadata for all maven repositories. This task was manually configured in nexus.
# the id was obtained running `curl -v -u admin:***** -X GET http://my-company/nexus/service/rest/v1/tasks`
# the recreate-maven-repos needs only the nx-tasks-run privilege
curl -q -u recreate-maven-repos:recreate -X POST http://my-company/nexus/service/rest/v1/tasks/c42ab5f5-4bd6-4ed3-b2f1-d061c24a9b90/run