如何将jar发布到本地存储库?
我有一个编译为 jar 的库(不是 sbt 项目,没有源代码,只有 jar 文件),该库在存储库中不可用。
有没有办法在本地发布 jar,以便我可以使用 libraryDependency += "org.xxx" % "xxx" % "1.0"
表示法添加依赖项? (我已经知道如何通过将文件复制到 lib
文件夹来将其添加到项目中。)
I have a library compiled to a jar (not an sbt project, no source code, just the jar file) that's not available on a repository.
Is there a way to publish the jar locally so I can add the dependency using the libraryDependencies += "org.xxx" % "xxx" % "1.0"
notation? (I already know how to add the file to a project by copying it to the lib
folder.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
publishLocal 操作用于将项目发布到本地 Ivy 存储库。默认情况下,此本地存储库位于 ${user.home}/.ivy2/local 中。然后,您可以在同一台计算机上的其他项目中使用该项目 源
编辑: 抱歉我看错你的问题了。这是一个将 jar 或源发布到本地 ivy 存储库的示例。
The publishLocal action is used to publish your project to a local Ivy repository. By default, this local repository is in ${user.home}/.ivy2/local. You can then use this project from other projects on the same machine source
EDIT: Sorry I misread your question. Here is an example to publish a jar or sources to your local ivy repo.
tl;dr 我认为这是一个技巧,而不是 sbt 的功能。你已被警告过。
假设您有要发布的
file.jar
。与任何构建工具(包括 sbt)一样,它执行最终从项目文件中创建工件(大多数情况下是 jar 文件)的任务。该项目设置工件的坐标。
诀窍是利用 sbt 所需的内容来设置要发布的 jar 的环境(= 坐标)(否则您必须在命令行上指定它们)这可能对用户很友好,也可能不太友好)。
使用必要的设置创建一个
build.sbt
-organization
、name
、version
以及可能的scalaVersion< /code> - 并将其保存在 jar 文件所在的位置。
您可能已经注意到,构建将
compile:package
任务更改为指向 jar 文件。就是这样。
执行
sbtpublishLocal
,jar文件应该在ivy2本地存储库中,即~/.ivy2/local/org.abc/my-own-publish-jar_2.11/1.0.0 /jars/my-own-publish-jar_2.11.jar
。protip 编写一个插件来使用命令行上指定的坐标来完成此操作现在应该非常容易。
tl;dr I'd call it a trick not a feature of sbt. You've been warned.
Let's say you've got
file.jar
to publish. As is for any build tool, sbt including, it's to execute tasks that eventually create an artifact - a jar file in most cases - out of the files in a project.The project sets the coordinates for the artifact.
The trick is to leverage what sbt requires to set up the environment (= the coordinates) for the jar to be published (otherwise you'd have to specify them on command line that may or may not be very user friendly).
Create a
build.sbt
with the necessary settings -organization
,name
,version
and possiblyscalaVersion
- and save it where the jar file is.You may've noticed, the build changes
compile:package
task to point at the jar file.That's it.
Execute
sbt publishLocal
and the jar file should be in the Ivy2 local repository, i.e.~/.ivy2/local/org.abc/my-own-publish-jar_2.11/1.0.0/jars/my-own-publish-jar_2.11.jar
.protip Writing a plugin to do it with the coordinates specified on command line should be quite easy now.
假设您有
wetElephant.jar
和wetElephant-javadoc.jar
文件,其中包含一些第 3 方库和相应的 javadoc,您希望将其发布到本地存储库并从另一个项目引用它使用libraryDependency
sbttaskKey。这就是你需要做的。
wetElephant.jar
和wetElephant-javadoc.jar
)放入modules\wetElephant
在构建中定义项目.sbt 文件(或 Build.scala 文件)
调用
publishLocal
任务来自 sbt/activator (我是从 activator 做的,并用项目名称作为前缀):...并读取输出以查看发布的内容和位置:
可以选择在另一个项目中使用这些库
免责声明:我不知道如何不发布源代码...
Let's say you have
wetElephant.jar
andwetElephant-javadoc.jar
files some 3rd party library and corresponding javadocs which you want to publish to your local repo and referrence it from another project usinglibraryDependencies
sbt taskKey.Here's what you need to do.
wetElephant.jar
andwetElephant-javadoc.jar
) intomodules\wetElephant
Define project in your build.sbt file (or Build.scala file)
Call
publishLocal
task from sbt/activator (I did it from activator and prefixed it with proejct name):... and read the output to see what and where was published:
Optionally use these libraries in another project
Disclaimer: I don't know how not to publish sources...
这是几个月前我关注的一篇博客文章,将 sbt 工件推送到 Maven 存储库(本地和远程)。
http://brizzled.clapper.org/id/100/
Here is a blog post I followed to push sbt artifact to a maven repository (local and remote) a few months ago.
http://brizzled.clapper.org/id/100/
试试这个:
http://maven.apache.org/指南/mini/guide-3rd-party-jars-local.html
Try this:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
我创建了一个示例 Play Framework/sbt 项目,该项目在此处创建本地存储库(不仅仅是
publish-local
):https://github.com/muymoo/local-ivy-repo-sbt具体看
Build.scala
makeLocalRepoSettings(已发布项目):_*
和
<代码>
localRepoArtifacts +=“org.apache.ws.security”%“wss4j”%“1.6.9”
这些
localRepoArtifacts
在我的本地 ivy 存储库中找到,但我认为您也可以编辑它以使用普通的旧 jar 文件。运行:
play local-repository-created
它是 https 的更简单版本://github.com/sbt/sbt-remote-control 在其
Build.scala
中做了更多的事情。I created a sample Play Framework/sbt project that creates a local repository (not just
publish-local
) here: https://github.com/muymoo/local-ivy-repo-sbtSpecifically look at
Build.scala
makeLocalRepoSettings(publishedProjects):_*
and
localRepoArtifacts += "org.apache.ws.security" % "wss4j" % "1.6.9"
These
localRepoArtifacts
are found in my local ivy repo, but I think you could edit this to work with plain old jar files as well.To run:
play local-repository-created
It is a simpler version of https://github.com/sbt/sbt-remote-control which does a whole lot more in their
Build.scala
.