gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:33:20 26 4
gpt4 key购买 nike

我知道如果在定义一个依赖项时添加 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项目后,我不需要手动配置它。

最佳答案

您必须更改引导属性。最近的博客里有一个很好的描述decodified 来自 Mathias :
How to make SBT download scala library sources ”(从@hseeberger关键起点开始)

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

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).



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

见 SO 问题“ how do I get sbt to use a local maven proxy repository (Nexus)?

关于scala - 如何让sbt下载scala-library.jar的源码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com