0

我尝试将自定义工件从 SBT 发布到 JFrog 工件。我有以下项目:SBT 版本 1.4.3

项目/plugins.sbt:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")

build.sbt (我简化了一点实际的)

ThisBuild / scalaVersion := "2.11.12"
ThisBuild / organization := "my.org"
ThisBuild / organizationName := "company"

lazy val root = (project in file(".")).settings(
   name := "my-project"
)

publishTo := {
  val artifactory = "https://artifactory.company.org/artifactory/repo"
  if (isSnapshot.value)
    Some(
      "Artifactory Realm" at s"$artifactory-snapshots;build.timestamp=" + new java.util.Date().getTime
    )
  else
    Some("Artifactory Realm" at s"$artifactory-releases;keep_forever=release-artifact")
}

artifact in (Compile, assembly) := {
  val art = (artifact in (Compile, assembly)).value
  art.withClassifier(Some("assembly"))
}

addArtifact(artifact in (Compile, assembly), assembly)

val packAnsible = taskKey[File]("Pack ansible files.")
val ansibleArtifactName = settingKey[String]("Ansible artifact name")

packAnsible := {
  val ansibleZip =
    target.value / s"scala-${scalaBinaryVersion.value}" / s"${name.value}.zip"
  IO.zip(
    IO.listFiles(Path("ansible").asFile).map(f => (f, f.name)),
    ansibleZip,
    None
  )
  ansibleZip
}
artifact in packAnsible := Artifact(name.value, "zip", "zip").withClassifier(Some("ansible"))

addArtifact(artifact in packAnsible, packAnsible)

如您所见,我添加了 2 个要发布的工件:

  1. 带有分类器“程序集”的 uber jar
  2. 带有一些带有分类器“ansible”的ansible vars的zip

在我的存储库中发布后,我几乎可以找到我想要的所有内容:

  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-assembly.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-javadoc.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1-sources.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1.jar
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-20210301.161254-1.pom
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/my-project_2.11-0.1.0-0.3.2-SNAPSHOT-ansible.zip
  • repo/com/org/my-project_2.11/0.1.0-SNAPSHOT/maven-metadata.xml

我可以在 maven-metadata 中看到除我的 zip 之外的所有其他工件,并且 jar 的名称不包含 build.time,因此在下一次构建时将失败,除非我授予用户覆盖/删除的权限,我不喜欢至。

我尝试遵循文档 并将其添加-Dsbt.override.build.repos=true到我的构建服务器中/usr/local/etc/sbtopts和项目的根目录中。

我希望正确发布所有工件(只有我的服装目前没有)。

谢谢您的帮助。

4

1 回答 1

0

显然问题出在我用于自定义工件的名称中:

artifact in packAnsible := Artifact(name.value, "zip", "zip").withClassifier(Some("ansible"))

应该:

artifact in packAnsible := Artifact((Compile / packageBin / artifact).value.name, "zip", "zip")
  .withClassifier(Some("ansible"))

我在实际构建中.有所不同。-

于 2021-03-01T20:39:43.763 回答