简体   繁体   English

SBT 在 Artifactory Maven 存储库中找不到快照

[英]SBT cannot find snapshots in an Artifactory maven repository

I'm just starting out trying to set up a workflow with scala and sbt, and I'm having trouble with my repository.我刚刚开始尝试使用 Scala 和 sbt 设置工作流程,但我的存储库遇到了问题。 I am trying to publish a simple test library, which is composed of two projects, and use it from another program.我正在尝试发布一个简单的测试库,它由两个项目组成,并从另一个程序中使用它。

My source library's build contains the following:我的源库的构建包含以下内容:

val sharedSettings = Seq(
  name := "test-lib",
  organization := "com.example",
  version := "0.1-SNAPSHOT",
  scalaVersion := "2.11.0",
  publishTo := Some("Artifactory Realm" at "http://localhost:8081/artifactory/libs-snapshot-local"),
  publishMavenStyle := true,
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
)

lazy val root = project.in(file(".")).settings(sharedSettings: _*).aggregate(child1, child2)

lazy val sharedCode = project.settings(sharedSettings: _*)

val child1Settings = sharedSettings ++ Seq(unmanagedSourceDirectories in Compile <++= (unmanagedSourceDirectories in sharedCode) in Compile)

val child2Settings = sharedSettings ++ Seq(unmanagedSourceDirectories in Compile <++= (unmanagedSourceDirectories in sharedCode) in Compile)

lazy val child1 = project.settings(child1Settings: _*)

lazy val child2 = project.settings(child2Settings: _*)

I can run sbt publish okay, and it creates the directory com/example/test-lib/XXX in the repo.我可以运行 sbt publish ,它会在 repo 中创建目录com/example/test-lib/XXX

In my test program, I have the following:在我的测试程序中,我有以下内容:

scalaVersion := "2.11.0",

resolvers += "Artifactory Realm" at "http://localhost:8081/artifactory/libs-snapshot-local",

libraryDependencies += "com.example" %% "test-lib" % "0.1-SNAPSHOT"

When the test program attempts to compile, it cannot resolve com.example , because of the following:当测试程序尝试编译时,它无法解析com.example ,原因如下:

[warn] ==== Artifactory Realm: tried
[warn]   http://localhost:8081/artifactory/libs-snapshot-local/com/example/test-lib_2.11/0.1-SNAPSHOT/test-lib_2.11-0.1-SNAPSHOT.pom

Looking at the repository directory itself, I am getting an additional timestamp on my pom files:查看存储库目录本身,我在我的 pom 文件上获得了一个额外的时间戳:

test-lib_2.11-0.1-20140510.183027-1.pom               10-May-2014 19:30  793 bytes
test-lib_2.11-0.1-20140510.183027-2.pom               10-May-2014 19:30  793 bytes
...
test-lib_2.11-0.1-20140510.183121-9.pom               10-May-2014 19:31  793 bytes

maven-metadata.xml in the directory is referencing these okay, sbt is looking directly for a pom file without a timestamp and cannot find it.目录中的maven-metadata.xml引用这些还好,sbt是直接找没有时间戳的pom文件,找不到。 The pom files contain the correct information. pom 文件包含正确的信息。

What am I doing wrong?我究竟做错了什么?

The issue was not with my sbt configuration after all, but with my repository server.毕竟问题不在于我的 sbt 配置,而在于我的存储库服务器。

I'm using Artifactory, and the snapshots repository was configured to use "unique snapshots" by default.我正在使用 Artifactory,默认情况下,快照存储库配置为使用“唯一快照”。 The filenames of these snapshots are modified as they are published to include a timestamp, which sbt 13.x doesn't seem to understand.这些快照的文件名在发布时被修改为包含时间戳,sbt 13.x 似乎无法理解。

After changing the repository's "Maven Snapshot Version Behaviour" from "Unique" to "Nonunique", everything started to work.将存储库的“Maven Snapshot Version Behaviour”从“Unique”更改为“Nonunique”后,一切都开始工作了。

actually, the inconsistency of timestamp & build number suffix in maven-metadata.xml and jar/pom files genereated by sbt publish lead to such error.实际上, sbt publish生成的 maven-metadata.xml 和 jar/pom 文件中的时间戳和内部版本号后缀不一致导致了此类错误。

在此处输入图片说明

with the following plugin sbt-maven-resolver during deployment procedure, the suffix will be kept same, looks like:在部署过程中使用以下插件sbt-maven-resolver ,后缀将保持不变,如下所示:

在此处输入图片说明

currently, adding this plugin on the deployment side (once the timestamp & build suffix are same, both sbt/maven can find the snapshots):目前,在部署端添加这个插件(一旦时间戳和构建后缀相同,sbt/maven 都可以找到快照):

in plugins.sbtplugins.sbt

addSbtPlugin("org.scala-sbt" % "sbt-maven-resolver" % "0.1.0")

hope to solve your case.希望能解决你的案子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM