如何让sbt下载scala-library.jar的源码?

发布于 2024-10-08 09:34:25 字数 320 浏览 4 评论 0原文

我知道如果我在定义一个依赖项时添加 withSources,sbt 可以自动下载该源 jar 文件。 例如,

val specs = "org.scala-tools.testing" % "specs_2.8.1" % "1.6.6" % "test" withSources ()

但是对于 scala-library.jar 和 scala-compiler.jar,我不这样做需要明确定义它们,我怎样才能让 sbt 为我下载它们的源代码?因此,在使用 sbt-idea-plugin 生成 idea 项目后,我不需要手动配置它。

I know if I add withSources when I define one dependency, sbt can download that sources jar file automatically.
For example,

val specs = "org.scala-tools.testing" % "specs_2.8.1" % "1.6.6" % "test" withSources ()

But for the scala-library.jar and scala-compiler.jar, I don't need define them explicitly, how can I get sbt download their sources for me? So, I don't need config it manually after generate idea project using sbt-idea-plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慢慢从新开始 2024-10-15 09:34:25

您必须更改启动属性。最近的博客 decodeified 来自 马蒂亚斯
如何让 SBT 下载 scala 库源”(从 @hseeberger 关键起点开始)


这是相关部分(以防链接过时)

首先,不要试图在 SBT 项目定义中找到一些“隐藏”设置来启用 Scala 库源下载!它不存在(至少在 SBT 0.7.x 版本中不存在)。
相反,您需要做以下两件事才能让 SBT 屈服:

  1. 为您的 SBT 启动器创建备用配置文件。
  2. 让 SBT 启动器使用它。

详细步骤如下:

  • 找到您的 sbt-launcher-0.7.x.jar 文件。
    因为我在 OS/X 上并通过 Homebrew 使用 SBT,所以我的生活位于 /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar.
  • 从启动器 jar 中的 sbt 子目录中提取 sbt.boot.properties
  • 启动您最喜欢的编辑器并将第 3 行更改为分类器:sources(取消注释该行)
  • 找到您在 SBT 设置期间创建的 sbt 脚本文件(例如 ~/bin/sbt,或者,当使用 Homebrew 时,/usr/local/Cellar/sbt/0.7.x /bin/sbt)
  • 将路径添加到调整后的 sbt.boot.properties 文件中,前面加上“@”字符并用双引号引起来,作为倒数第二个参数java 调用。

这就是我的 sbt 脚本文件的样子:

#!/bin/sh
java -Xmx768M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m \
     -jar /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar \
     "@/usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt.boot.properties" \
     "$@"

完成这些步骤后,SBT 应该会愉快地为您创建的任何新项目下载 Scala 编译器和标准库的 scala-...-sources.jar 文件。
要让 SBT 对现有项目执行此操作,您必须在执行“sbt update<”之前手动删除 project/boot/scala-{version} 目录/code>'(如果主 jar 已经存在,SBT 不会获取其他源工件)。


一旦您拥有自定义 sbt.boot.properties 文件,还可以通过其他方式将其提供给 SBT 启动器。

请参阅SO问题“如何让 sbt 使用本地 Maven 代理存储库 (Nexus)?"

You have to change the boot properties. There is a nice description in the recent blog decodified from Mathias:
"How to make SBT download scala library sources" (started from @hseeberger key starting points)


Here is the relevant part (in case that link ever goes stale)

First, forget about trying to find some “hidden” setting in your SBT project definition enabling Scala library source download! It does not exist (at least not in SBT version 0.7.x).
Rather, there are these two things you need to do in order to whip SBT into submission:

  1. Create an alternative configuration file for your SBT launcher.
  2. Make the SBT launcher use it.

These are the steps in detail:

  • Find your sbt-launcher-0.7.x.jar file.
    Since I’m on OS/X and use SBT via Homebrew mine lives at /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar.
  • Extract the sbt.boot.properties from the sbt sub directory in the launcher jar
  • Fire up your favorite editor and change line 3 to classifiers: sources (uncomment the line)
  • Find the sbt script file you created during your SBT setup (e.g. ~/bin/sbt, or, when using Homebrew, /usr/local/Cellar/sbt/0.7.x/bin/sbt)
  • Add the path to your tweaked sbt.boot.properties file, prepended with an ’@’ character and in double quotes, as the second-to-last argument of the java call.

This is what my sbt script file looks like:

#!/bin/sh
java -Xmx768M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m \
     -jar /usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt-launch-0.7.5.RC0.jar \
     "@/usr/local/Cellar/sbt/0.7.5.RC0/libexec/sbt.boot.properties" \
     "$@"

Once you have completed these steps SBT should happily download the scala-...-sources.jar files for the Scala compiler and standard library for any new project you create.
To have SBT do this for an existing project, you have to manually delete the project/boot/scala-{version} directory before performing an ‘sbt update’ (SBT does not fetch additional source artifacts if the main jar is already present).

Once you have a custom sbt.boot.properties file, there are also other ways to supply it to the SBT launcher.

See SO question "how do I get sbt to use a local maven proxy repository (Nexus)?"

空宴 2024-10-15 09:34:25

根据 Michael Slinn 的评论:

如果您使用 sbt 0.11.x 及更高版本,请使用以下命令:

sbt update-sbt-classifiers

Based on Michael Slinn comments:

If you are using sbt 0.11.x and above, use this command:

sbt update-sbt-classifiers
夏の忆 2024-10-15 09:34:25

两条信息。

(1) SBT文档
http://www.scala-sbt.org /0.13.5/docs/Detailed-Topics/Library-Management.html

我引用:
“要以传递方式获取所有依赖项的特定分类器,请运行 updateClassifiers 任务。默认情况下,这将解析具有源或 javadoc 分类器的所有工件。”

这意味着您不需要执行任何操作,但您可以将其明确并放入 build.sbt 中:
transitiveClassifiers := Seq("sources", "javadoc")

要实际获取 SBT 下载的源代码,请执行以下操作:

“更新分类器”

(2) 如果您正在使用 Eclipse scala IDE - 最有可能的是,因为 Eclipse/Netebeans 插件的开发对于 eclipse 来说更加活跃 - 那么您应该配置您的 ecplise 来找出源代码,如果您执行以下操作下列的。
EclipseKeys.withSource := true
这是您应该阅读的文档,
https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse

Two pieces of information.

(1) SBT Documentation
http://www.scala-sbt.org/0.13.5/docs/Detailed-Topics/Library-Management.html

and I quote:
"To obtain particular classifiers for all dependencies transitively, run the updateClassifiers task. By default, this resolves all artifacts with the sources or javadoc classifier."

This means you should not need to do anything, but you can make it explicit and put in you build.sbt:
transitiveClassifiers := Seq("sources", "javadoc")

To actually get the sources downloaded by SBT then you do:

"updateClassifiers"

(2) If you are working with Eclipse scala IDE - most likely you are as development of plugins for Eclipse/Netebeans is a lot more active for eclipse - then you should configure your ecplise to find out the sources if you do the following.
EclipseKeys.withSource := true
Here is the documentation you should read,
https://github.com/typesafehub/sbteclipse/wiki/Using-sbteclipse

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文