我正在尝试将使用sbt-native-packager构建的rpm发布到由Artifactory托管的yum存储库。我的项目使用JavaAppPackaging Archetype。我想发布到我的yum repo的路径,即/ rhel / linux / 7 / x86_64。不幸的是,它总是发布到类似maven的路径/artifactId/version/mypackage-version-arch.rpm
我可以改变一些设置来实现这个目标吗?
答案 0 :(得分:0)
现在已经设置好了,我觉得我可以并且应该在这里发布答案。
首先,有一些假设:
1.我们正在发布到Nexus。 (制造商应该相似,但此处显示的是适用于Nexus的产品。)
2. Nexus需要凭据才能发布。这使问题变得复杂,因此我们覆盖了publish
任务以直接提供凭据。
3.我们正在构建服务器应用程序,因此是JavaServerAppPackaging
。进行适当的修改。
4.作为服务器应用程序的一部分,我们需要一个启动脚本。在这种情况下,我们使用的是system-v,因此使用ServerLoader.SystemV
。由于大多数较新的Linux使用Systemd,请进行适当的修改。
5.您想使用sbt-release
插件来自动发布。
6.我们的应用程序是模块化的,因此我们使用的是多模块sbt构建。
build.sbt
内容:
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 = ...