是否有人使用sbt-aether-deploy向nexus repo发布了一个sbt-native-packager生成的工件(在我的情况下为tgz)? (我需要这个用于时间戳快照,特别是nexus'artifact-resolution REST资源中的“正确”版本标记。)
我可以做其中一个但是无法弄清楚如何将通用中的 packagedArtifacts添加到sbt-aether-deploy部署的工件中。
我怀疑追求的路径是addArtifact()通用中的 packagedArtifacts,还是创建另一个AetherArtifact,然后覆盖/替换deployTask以使用该AetherArtifact?
任何帮助非常感谢。
答案 0 :(得分: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"。我们将看看是否可以改变这一特定部分。
答案 1 :(得分:1)
好的,我觉得我的表现非常出色。如果有更好的方法,我很乐意听。不喜欢盲目的选择。那里..
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 :(得分: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后缀。