一種選擇是定義一個子項目爲您要發佈的每個罐子。你的主要項目取決於每個項目。給每個子項目一個合適的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