2013-10-10 54 views

回答

4

一种选择是定义一个子项目为您要发布的每个罐子。你的主要项目取决于每个项目。给每个子项目一个合适的name,versionorganization。对于每个子项目,将其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定义为独立项目。

+0

有没有办法发布多个罐子? – hanxue

+0

我得到'java.lang.RuntimeException:未指定发布的版本库' – Havnar

+0

@Havnar正确,定义发布到哪里不包括在此答案中。幸运的是,这很容易。 – Marcin