3

有没有人使用 sbt-aether-deploy 将 sbt-native-packager 生成的工件(在我的情况下为 tgz)发布到 nexus 存储库?(我需要这个用于时间戳快照,特别是 nexus 的工件解析 REST 资源中的“正确”版本标签)。

我可以做一个或另一个,但无法弄清楚如何将Universal中的 packagedArtifacts 添加到 sbt-aether-deploy 部署的工件中以完成这两个任务。

我怀疑要追求的路径是 addArtifact()通用中的 packagedArtifacts或创建另一个 AetherArtifact 然后覆盖/替换 deployTask 以使用该 AetherArtifact?

非常感谢任何帮助。

4

3 回答 3

2

我是 sbt-aether-deploy 插件的作者,我刚看完这篇文章。

import aether.AetherKeys._

crossPaths := false //needed if you want to remove the scala version from the artifact name

enablePlugins(JavaAppPackaging)

aetherArtifact := {
    val artifact = aetherArtifact.value
    artifact.attach((packageBin in Universal).value, "dist", "zip")
}

这也将发布另一个主要工件。

如果要禁用主要工件的发布,则需要重写工件坐标。Maven 需要一个主工件。

为此,我添加了一种替换主要工件的方法,但我现在可以看到这种方法有点缺陷。它仍会假定工件是作为 jar 文件发布的。主要工件类型被锁定,因为 SBT 默认将 POM 打包设置为 jar。

如果这是一个应用程序,那么这种限制可能是可以的,因为 Maven 永远不会将其解析为工件。

Maven 术语中的“正确”方式是将分类器添加到工件并将 POM 文件中的“打包”更改为“pom”。我们将看看我是否有时间改变那个特定的部分。

于 2017-09-05T21:31:57.140 回答
1

我采用了彼得的解决方案并对其进行了轻微修改,Option.get通过直接创建来避免裸露MavenCoordinates

import aether.MavenCoordinates
import aether.Aether.createArtifact

name := "mrb-test"

organization := "me.mbarton"

version := "1.0"

crossPaths := false

packageArchetype.java_application

publish <<= (publish) dependsOn (publish in Universal)

publishLocal <<= (publishLocal) dependsOn (publishLocal in Universal)

aetherPublishBothSettings

aetherArtifact <<= (organization, name in Universal, version, packageBin in Universal, makePom in Compile, packagedArtifacts in Universal) map {
    (organization, name, version, binary, pom, artifacts) =>
        val nameWithoutVersion = name.replace(s"-$version", "")
        createArtifact(artifacts, pom, MavenCoordinates(organization, nameWithoutVersion, version, None, "zip"), binary)
}

nameWithoutVersion替换适用于 SBT 本机打包程序,包括工件名称中的版本:

  • 之前me/mbarton/mrb-test-1.0/1.0/mrb-test-1.0.zip
  • 之后me/mbarton/mrb-test/1.0/mrb-test-1.0.zip

crossPaths避免版本上的 Scala 后缀。

于 2014-05-16T13:33:44.367 回答
1

好吧,我想我已经足够惊人了。如果有更好的方法,我很乐意听到。不喜欢那个盲目的Option.get there..

  val tgzCoordinates = SettingKey[MavenCoordinates]("the maven coordinates for the tgz")

  lazy val myPackagerSettings = packageArchetype.java_application ++ deploymentSettings ++   Seq(
    publish <<= publish.dependsOn(publish in Universal),
    publishLocal <<= publishLocal.dependsOn(publishLocal in Universal)
  )

  lazy val defaultSettings = buildSettings ++ Publish.settings ++  Seq(
    scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.7", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls"),
    testOptions in Test += Tests.Argument("-oDF")
  )

  lazy val myAetherSettings = aetherSettings ++ aetherPublishBothSettings

  lazy val toastyphoenixProject = Project(
    id = "toastyphoenix",
    base = file("."),
    settings = defaultSettings ++ myPackagerSettings ++ myAetherSettings ++ Seq(
      name in Universal := name.value + "_" + scalaBinaryVersion.value,
      packagedArtifacts in Universal ~= { _.filterNot { case (artifact, file) => artifact.`type`.contains("zip")}},
      libraryDependencies ++= Dependencies.phoenix,
      tgzCoordinates := MavenCoordinates(organization.value + ":" + (name in Universal).value + ":tgz:" + version.value).get,
      aetherArtifact <<= (tgzCoordinates, packageZipTarball in Universal, makePom in Compile, packagedArtifacts in Universal) map {
        (coords: MavenCoordinates, mainArtifact: File, pom: File, artifacts: Map[Artifact, File]) =>
          createArtifact(artifacts, pom, coords, mainArtifact)
      }
    )
  )
于 2014-04-18T05:13:47.060 回答