一种选择是定义一个子项目为您要发布的每个罐子。你的主要项目取决于每个项目。给每个子项目一个合适的name
,version
和organization
。对于每个子项目,将其jar放在不在类路径中的某个位置,并使packageBin
的输出成为该jar。
例如(SBT 0.13 build.sbt),
lazy val main = project.dependsOn(subA)
lazy val subA = project.settings(
name := "third-party",
organization := "org.example",
version := "1.4",
packageBin in Compile := baseDirectory.value/"bin"/"third-party.jar",
// if there aren't doc/src jars use the following to
// avoid publishing empty jars locally
// otherwise, define packageDoc/packageSrc like packageBin
publishArtifact in packageDoc := false,
publishArtifact in packageSrc := false,
// tell sbt to put the jar on main's classpath
// and not the (empty) class directory
exportJars := true,
// set this to not add _<scalaBinaryVersion> to the name
crossPaths := true
)
这种方法允许你改变罐子在subA/bin/third-party.jar
并将它立即使用,并随后将publishLocal
本地发布。
如果您希望单独在本地发布它,以便它不属于该项目,请将subA
定义为独立项目。
有没有办法发布多个罐子? – hanxue
我得到'java.lang.RuntimeException:未指定发布的版本库' – Havnar
@Havnar正确,定义发布到哪里不包括在此答案中。幸运的是,这很容易。 – Marcin