12

我正在尝试在我的个人网络服务器上发布我的一些 SBT 项目。据我所知,您通常将 SBT 项目导出为包含项目定义的 POM.xml 的 Maven 目录。

正如Brian Clapper 所指出的,您可以通过创建多个配置文件并使用sbt publish. 在他的教程中,存储库是通过 FTP 传输的。

我想手动将我的 Maven 存储库推送到服务器,以便拥有更多控制权。你能给我一些提示,如何做到这一点?

4

2 回答 2

20

我想出了如何做到这一点。此解决方案创建一个与 Maven 兼容的本地 Ivy 存储库。

您必须在 中设置以下值build.sbt

name := "project-name"

organization := "org.example"

version := "0.0.0"

scalaVersion := "2.9.2"

publishTo := Some(Resolver.file("file", new File("/path/to/your/releases"))

之后,您可以发布您的版本

sbt publish

这将打印类似于以下行的内容

[info] Set current project to project-name (in build file:/path/to/your/project/)
[info] Updating {file:/path/to/your/project/}default-2e51ea...
[info] Packaging /path/to/your/project/target/scala-2.9.2/project-name_2.9.2-0.0.0-S
NAPSHOT-sources.jar ...
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Done packaging.
[info] Done updating.
[info] :: delivering :: org.example#project-name_2.9.2;0.0.0 :: 0.0.0 :: release :: Tue Jul 24 15:41:04 CEST 2012
[info]  delivering ivy file to /path/to/your/project/target/scala-2.9.2/ivy-0.0.0.xml
[info] Wrote /path/to/your/project/target/scala-2.9.2/project-name_2.9.2-0.0.0.pom
[info] Packaging /path/to/your/project/target/scala-2.9.2/project-name_2.9.2-0.0.0.jar ...
[info] Done packaging.
[info]  published project-name_2.9.2 to /path/to/your/releases/org/example/project-name_2.9.2/0.0.0-SNAPSHOT/project-name_2.9.2-0.0.0.pom
[info]  published project-name_2.9.2 to /path/to/your/releases/org/example/project-name_2.9.2/0.0.0-SNAPSHOT/project-name_2.9.2-0.0.0.jar
[info]  published project-name_2.9.2 to /path/to/your/releases/org/example/project-name_2.9.2/0.0.0-SNAPSHOT/project-name_2.9.2-0.0.0-sources.jar
[info]  published project-name_2.9.2 to /path/to/your/releases/org/example/project-name_2.9.2/0.0.0-SNAPSHOT/project-name_2.9.2-0.0.0-javadoc.jar
[success] Total time: 1 s, completed 24.07.2012 15:41:05

您可以将生成的文件放在任何 Web 服务器上(例如http://repo.example.org/),并在另一个项目的构建脚本中使用它,方法是将以下行添加到您的build.sbt:

resolvers += "Personal repository" at "http://repo.example.org/"

libraryDependencies += "org.example" % "project-name" % "0.0.0"

For more information, see SBT: Getting Started Library Dependencies and SBT: Publishing.

于 2012-07-24T14:14:04.737 回答
8

从 sbt,您可以使用

project myproject
[myproject] $ publish-local

它将发布到您当地的常春藤目录(通常~/.ivy2/local)。

在输出中,您将看到所有文件的路径:

[info] Done packaging.
[info] published myproject_2.9.1 to .../ivy2/...myproject.../poms/myproject_2.9.1.pom
[info] published myproject_2.9.1 to .../ivy2/...myproject.../jars/myproject_2.9.1.jar
[info] published myproject_2.9.1 to .../ivy2/...myproject.../srcs/myproject_2.9.1-sources.jar
[info] published myproject_2.9.1 to .../ivy2/...myproject.../docs/myproject_2.9.1-javadoc.jar
[info] published ivy to .../ivy2/...myproject.../ivys/ivy.xml

然后你可以抓取这些文件并将它们上传到你的 ftp 服务器。

不过,我仍然会推荐链接的博客文章中描述的方法。至少我们是这样做的。只是关于存储凭据的一个小说明。使用以下 sbt 设置:

val credentials = Credentials(Path.userHome / ".ivy2" / ".my-credentials")

凭据文件将如下所示:

realm=Sonatype Nexus Repository Manager
host=nexus.example.com
user=deployment
password=pass

凭据与您用于登录 Nexus Web 界面的凭据相同。

于 2012-07-15T15:00:42.273 回答