首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用sbt-native-packager将rpm发布到Artifactory托管的Yum存储库?

如何使用sbt-native-packager将rpm发布到Artifactory托管的Yum存储库?
EN

Stack Overflow用户
提问于 2015-01-30 06:38:00
回答 1查看 661关注 0票数 2

我正在尝试将使用sbt-native-packager构建的rpm发布到Artifactory托管的yum存储库。我的项目使用JavaAppPackaging原型。我想发布到我的yum代码库的路径,即/rhel/linux/7/x86_64。不幸的是,它总是发布到类似maven的路径/artifactId/version/mypackage-version-arch.rpm

有没有什么我可以改变的设置来完成这个任务?

EN

回答 1

Stack Overflow用户

发布于 2019-08-15 01:32:12

现在已经设置好了,我觉得我可以也应该在这里发布一个答案。

首先,有几个假设: 1.我们将发布到Nexus。(Artifactory应该类似,但这里显示的是适用于Nexus的内容。) 2. Nexus需要凭据才能发布。这使问题变得复杂,因此我们覆盖publish任务以直接提供凭据。3.我们正在构建一个服务器应用程序,因此是JavaServerAppPackaging。根据需要进行修改。4.作为服务器应用程序的一部分,我们需要一个启动脚本。在本例中,我们使用system-v,因此使用ServerLoader.SystemV。适当修改,因为大多数较新的Linuxes都使用Systemd。5.你想要使用sbt-release插件来自动发布。6.我们的应用是模块化的,因此我们使用多模块sbt构建。

build.sbt内容:

代码语言:javascript
复制
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import NativePackagerHelper._
import ReleaseTransformations._
import scala.sys.process._

// Top-level settings

name := "project-name"
organization in ThisBuild := "com.example"
scalaVersion in ThisBuild := "2.12.8"


// Integrating with sbt-release plugin   
releasePublishArtifactsAction := {(publish in Rpm).value}

lazy val publishRpmUrl = Def.setting {
  val nexus = "http://nexus.example.com"
  if (version.value.trim.endsWith("SNAPSHOT"))
    ("test-yum-repo", url(nexus + "/repository/test-yum-repo/"))
  else
    ("prod-yum-repo", url(nexus + "/repository/prod-yum-repo/"))
}

// Keep the release plugin happy by having this key set, but disallow remote publishing since
// nothing in this project is sharable.
Global / publishTo := {Option(Resolver.mavenLocal)}

// Settings for root project

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

    // Top-level publishing settings

    publishArtifact in Rpm := true,
    publishLocal in Rpm := {},

    // Standard publish doesn't appear to pass credentials
    publish in Rpm := {
      val creds = Credentials.toDirect(Credentials(Path.userHome / ".sbt" / "nexus.credentials"))
      val (_, destUrl) = publishRpmUrl.value

      Process(
      "curl" :: "-v" ::
        "-u" :: s"${creds.userName}:${creds.passwd}" ::
        "--upload-file" :: (packageBin in Rpm).value.getAbsolutePath ::
        destUrl.toString :: Nil
      ) ! streams.value.log
    },

    // Top-level settings

    mainClass in Compile := Some("com.example.app.Main"),

    // RPM settings

    // package settings
    maintainer := "Acme <info@example.com>",
    packageName in Rpm := "rpm-name",
    packageSummary in Rpm := "Some Summary",
    packageDescription in Rpm := "Some Description",

    // rpm specific
    rpmVendor := "Acme",
    rpmUrl := Some("http://example.com/"),
    rpmLicense := Some("Copyright © 2019 Acme Inc. All Rights Reserved."),
    rpmRequirements ++= Seq("java-1.8.0-openjdk", "bash"),

    linuxPackageMappings in Rpm := configWithNoReplace((linuxPackageMappings in Rpm).value),

    // Java Server Application Archetype
    daemonUser in Rpm := "app-daemon",
    daemonGroup in Rpm := "app-daemon",

    // System loader settings

    // WARN Newer systems will want to use a different loader!
    serverLoading := Some(ServerLoader.SystemV),
    serviceAutostart := true,

    mappings in Universal ++= directory( (sourceDirectory in server).value / "main" / "resources" )
  )
  // Package as normal java server for RedHat RPM running SystemV
  .enablePlugins(RpmPlugin,RpmDeployPlugin)
  .enablePlugins(JavaServerAppPackaging)
  .enablePlugins(SystemloaderPlugin, SystemVPlugin)
  .aggregate(server,client)
  .dependsOn(server,client)

lazy val server = ...
lazy val client = ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28226001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档