使用 sbt(第 3 方)发布 jar 文件 [英] publish jar files with sbt (3rd party)

查看:43
本文介绍了使用 sbt(第 3 方)发布 jar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hello I have 5 jar files and tried to publish them to a local repository with sbt. But when I place them in unmanagedBase directory like lib/ they won't get copied with publishLocal. Is there an easy way to include them in the publishing process?

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

Currently maven has a similar solution here: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

推荐答案

一种选择是为您要发布的每个 jar 定义一个子项目.让您的主要项目依赖于每个项目.给每个子项目一个合适的nameversionorganization.对于每个子项目,将它的 jar 放在不在类路径上的某个地方,并使 packageBin 的输出成为那个 jar.

One option is to define a subproject for each jar that you want published. Have your main project depend on each. Give each subproject an appropriate name, version, and organization. For each subproject, put its jar somewhere not on the classpath and make the output of packageBin be that jar.

例如(sbt 0.13 build.sbt),

For example (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 将在本地发布它.

This approach allows you to change the jar in subA/bin/third-party.jar and have it be used immediately and a subsequent publishLocal will publish it locally.

如果您更喜欢在本地单独发布它,使其不属于项目的一部分,请将 subA 定义为独立项目.

If you prefer separately publishing it locally, so that it isn't part of the project, define subA as a standalone project instead.

这篇关于使用 sbt(第 3 方)发布 jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆