scala 在哪里可以找到下载的 sbt 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27094610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:44:33  来源:igfitidea点击:

where to find downloaded library of sbt?

javascalasbt

提问by firstprayer

Where does sbt put the downloaded jar? I'm trying to ask sbt to download all dependencies and put them under lib/ directory so I can use them with the ScalaIDE, however after I ran sbt compilesuccessfully I don't know where to find these downloaded .jars

sbt把下载的jar放在哪里?我试图让 sbt 下载所有依赖项并将它们放在 lib/ 目录下,以便我可以将它们与 ScalaIDE 一起使用,但是在我sbt compile成功运行后我不知道在哪里可以找到这些下载的 .jars

采纳答案by axel22

All new SBT versions (after 0.7.x) by default put the downloaded JARS into the .ivy2directory in your home directory.

0.7.x默认情况下,所有新的 SBT 版本(在 之后)都将下载的 JARS 放入.ivy2您的主目录中的目录中。

If you are using Linux, this is usually /home/<username>/.ivy2/cache.

如果您使用的是 Linux,这通常是/home/<username>/.ivy2/cache.

If you are using Windows, this is usually c:\Users\<username>\.ivy2\cache.

如果您使用的是 Windows,这通常是c:\Users\<username>\.ivy2\cache.

EDIT:

编辑:

Here's an example from one of my projects, in which I define an SBT task that copies the dependencies into the target folder. You can place this code into your project/Build.scalaproject definition file. You should have something like this in your project definition file (more info at www.scala-sbt.org):

这是我的一个项目中的一个示例,我在其中定义了一个 SBT 任务,该任务将依赖项复制到目标文件夹中。您可以将此代码放入您的project/Build.scala项目定义文件中。您的项目定义文件中应该有类似的内容(更多信息请访问 www.scala-sbt.org):

import sbt._
import Keys._
import Process._

object MyProjectBuild extends Build {

The following code copies all your libraries to a deploy/libzsubdirectory, by defining a deploytask that captures your program artifact and all its classpath dependencies:

以下代码deploy/libz通过定义deploy捕获程序工件及其所有类路径依赖项的任务,将所有库复制到子目录中:

val deployKey = TaskKey[Unit](
  "deploy",
  "Deploys the project in the `deploy` subdirectory."
)

val deployTask = deployKey <<= (artifactPath in (Compile, packageBin), dependencyClasspath in Compile) map {
  (artifact, classpath) =>
  val deploydir = new File("deploy")
  val libzdir = new File("deploy%slib".format(File.separator))

  // clean old subdirectory
  deploydir.delete()

  // create subdirectory structure
  deploydir.mkdir()
  libzdir.mkdir()

  // copy deps and artifacts
  val fullcp = classpath.map(_.data) :+ artifact
  def lastName(file: File) = if (file.isFile) file.getName else file.getParentFile.getParentFile.getParentFile.getName
  for (file <- fullcp) {
    println("Copying: " + file + "; lastName: " + lastName(file))
    if (file.isFile) IO.copyFile(file, (libzdir / lastName(file)).asFile);
    else IO.copyDirectory(file, (libzdir / lastName(file)))
  }
} dependsOn (packageBin in Compile)

回答by Rollen Holt

I find the sbt dependency from http://mvnrepository.com/

我从http://mvnrepository.com/找到了 sbt 依赖项

for example, you want to find MySQL Java Connector, you can search form the search box, and choose a version you like, then you will see sbttag:

比如你想找MySQL Java Connector,你可以在搜索框里搜索,然后选择你喜欢的版本,然后你会看到sbt标签:

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.34"

if you want to find the downloaded jars, in windows is C:\Users\<userName>\.ivy2\cache

如果你想找到下载的 jars,在 windows 中是 C:\Users\<userName>\.ivy2\cache

in linux is ~/.ivy2/cache

在 linux 中是 ~/.ivy2/cache

good luck

祝你好运

回答by tabata

The reference below is useful for sbt.

下面的参考对 sbt 很有用。

https://www.scala-sbt.org/1.x/docs/Launcher-Configuration.html

https://www.scala-sbt.org/1.x/docs/Launcher-Configuration.html

You can find sbt.ivy.home is the parameter and default is ${user.home}/.ivy2/.

你可以发现 sbt.ivy.home 是参数,默认是 ${user.home}/.ivy2/。

...

[repositories] local typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/artifact.[ext], bootOnly maven-central sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots

[boot] directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}

[ivy] ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}

...

...

[存储库] 本地 typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/artifact.[ext], bootOnly maven-central sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots

[boot] 目录:${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/}

[ivy] ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/}

...