【问题标题】:Using sbt-aether-deploy with sbt-native-packager将 sbt-aether-deploy 与 sbt-native-packager 一起使用
【发布时间】:2014-06-02 13:04:16
【问题描述】:

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

我可以做一个或另一个,但不知道如何将 packagedArtifacts in Universal 添加到 sbt-aether-deploy 部署的工件以完成这两个任务。

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

非常感谢任何帮助。

【问题讨论】:

    标签: sbt sbt-native-packager


    【解决方案1】:

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

      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)
          }
        )
      )
    

    【讨论】:

      【解决方案2】:

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

      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 后缀。

      【讨论】:

      • 看起来以太有一些重大变化。这个答案有没有现代化的机会?
      • 在下面查看我的答案。
      【解决方案3】:

      我是 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-03-25
        • 2014-07-01
        • 2016-12-14
        • 2015-10-11
        • 2016-07-27
        • 2015-10-03
        • 2013-12-29
        • 2015-07-25
        • 2016-08-17
        相关资源
        最近更新 更多