【问题标题】:publish jar files with sbt (3rd party)使用 sbt 发布 jar 文件(第 3 方)
【发布时间】:2013-10-10 21:59:05
【问题描述】:

您好,我有 5 个 jar 文件并尝试使用 sbt 将它们发布到本地存储库。 但是当我将它们放在像lib/ 这样的unmanagedBase 目录中时,它们不会被publishLocal 复制。有没有一种简单的方法可以将它们包含在发布过程中?

目前maven在这里有类似的解决方案: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    一个选项是为每个要发布的 jar 定义一个子项目。让您的主要项目依赖于每个项目。给每个子项目一个合适的nameversionorganization。对于每个子项目,将其 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 中的 jar 并立即使用它,随后的 publishLocal 将在本地发布它。

    如果您希望将其单独发布到本地,使其不属于项目的一部分,请将 subA 定义为独立项目。

    【讨论】:

    • 有没有办法发布多个jar?
    • 我收到 'java.lang.RuntimeException: Repository for publishing is not specified'
    • @Havnar 正确,此答案未涵盖定义发布到的位置。幸运的是,这很容易。
    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 2014-05-29
    • 1970-01-01
    • 2018-02-26
    • 2018-01-07
    • 2019-03-12
    • 1970-01-01
    • 2016-12-15
    相关资源
    最近更新 更多