如何设置IntelliJ Idea Scala项目来识别本地Ivy2缓存? [英] How to set up an IntelliJ Idea Scala project to recognize local Ivy2 cache?

查看:125
本文介绍了如何设置IntelliJ Idea Scala项目来识别本地Ivy2缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您可能知道的那样,SBT的新版本(作为0.11)旨在维护〜/ .ivy2 / cache 中的公共库缓存,而不是复制整套项目目录中的依赖项。但IntelliJ Idea(我使用SBT插件生成一个Idea项目)默认似乎忽略了公共缓存,只看到放在项目目录下的库(所以,我必须配置SBT来执行这种传统方式)。如何解决这个问题?

As you probablu know, new versions of SBT (as 0.11) are designed to maintain a common libraries cache in ~/.ivy2/cache instead of copying the full set of dependencies inside a project directory. But IntelliJ Idea (I use the SBT plugin to generate an Idea project) default seems to be ignoring the common cache and only see the libraries put under the project directory (so, I have to configure SBT to act this legacy way). How to fix this?

Idea插件库中有一些常春藤插件,但我不知道它们中哪些(如果有的话)可以解决问题(注意)我不希望它管理依赖项并下载库(由SBT完成),只是为了在缓存中查找类。)

There are some Ivy plugins in the Idea plugin repository, but I don't know which (if any) of them can solve the problem (note that I don't want it to manage the dependencies and download the libraries (as it is done by SBT) but just to look for classes in the cache).

推荐答案

sbt-idea指的是 sbt 引用它们的位置中的库,默认情况下是〜 /.ivy2/cache

sbt-idea refers to the libraries in the locations that sbt refers to them, which by default is under ~/.ivy2/cache.

以下是我的系统的外观,包括一个新项目,SBT 0.11.2和sbt-idea 0.11.0:

Here's how it looks on my system, with a fresh project, SBT 0.11.2, and sbt-idea 0.11.0:

 ~/code/scratch/20120225 sbt
[info] Loading global plugins from /Users/jason/.sbt/plugins
[info] Set current project to default-d73535 (in build file:/Users/jason/code/scratch/20120225/)

> set libraryDependencies += "org.scalaz" %% "scalaz-core" % "6.0.3"
[info] Reapplying settings...
[info] Set current project to default-d73535 (in build file:/Users/jason/code/scratch/20120225/)

> session save
[info] Reapplying settings...
[info] Set current project to default-d73535 (in build file:/Users/jason/code/scratch/20120225/)

> gen-idea no-sbt-classifiers
[info] Trying to create an Idea module default-d73535
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving org.scalaz#scalaz-core_2.9.1;6.0.3 ...
[info] Excluding folder target
[info] Created /Users/jason/code/scratch/20120225/.idea/IdeaProject.iml
[info] Created /Users/jason/code/scratch/20120225/.idea
[info] Excluding folder /Users/jason/code/scratch/20120225/target
[info] Created /Users/jason/code/scratch/20120225/.idea_modules/default-d73535.iml
[info] Created /Users/jason/code/scratch/20120225/.idea_modules/project.iml

  ~/code/scratch/20120225 grep jar /Users/jason/code/scratch/20120225/.idea/libraries/*.xml
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-library.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$USER_HOME$/.ivy2/cache/org.scala-lang/scala-library/docs/scala-library-2.9.1-javadoc.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$USER_HOME$/.ivy2/cache/org.scala-lang/scala-library/srcs/scala-library-2.9.1-sources.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$USER_HOME$/.ivy2/cache/org.scalaz/scalaz-core_2.9.1/jars/scalaz-core_2.9.1-6.0.3.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$USER_HOME$/.ivy2/cache/org.scalaz/scalaz-core_2.9.1/docs/scalaz-core_2.9.1-6.0.3-javadoc.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$USER_HOME$/.ivy2/cache/org.scalaz/scalaz-core_2.9.1/srcs/scalaz-core_2.9.1-6.0.3-sources.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/scala_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-library.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/scala_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-compiler.jar!/"></root>

但是,SBT有一个配置设置, retrieve-managed 使用make构建所有库的构建本地副本,而不是直接从缓存中引用它们。如果启用此功能, sbt-idea 也会设置IntelliJ类路径以引用这些。

However, SBT has a configuration setting, retrieve-managed to use make a build-local copy of all libraries, rather than directly referring to them from the cache. If you have this enabled, sbt-idea will also setup the IntelliJ classpath to refer to these.

这是帮助:

> help retrieve-managed

If true, enables retrieving dependencies to the current build.  Otherwise, dependencies are used directly from the cache.

让我们试一试:

> set retrieveManaged in ThisBuild := true  
[info] Reapplying settings...
[info] Set current project to default-d73535 (in build file:/Users/jason/code/scratch/20120225/)
> update
[info] Updating {file:/Users/jason/code/scratch/20120225/}default-d73535...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving org.scalaz#scalaz-core_2.9.1;6.0.3 ...
[info] Done updating.
[success] Total time: 1 s, completed Feb 25, 2012 9:07:41 AM
> show compile:dependency-classpath
[info] Updating {file:/Users/jason/code/scratch/20120225/}default-d73535...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving org.scalaz#scalaz-core_2.9.1;6.0.3 ...
[info] Done updating.
[info] ArrayBuffer(Attributed(/Users/jason/.sbt/boot/scala-2.9.1/lib/scala-library.jar), Attributed(/Users/jason/code/scratch/20120225/lib_managed/jars/org.scalaz/scalaz-core_2.9.1/scalaz-core_2.9.1-6.0.3.jar))
[success] Total time: 0 s, completed Feb 25, 2012 9:07:54 AM


> gen-idea no-sbt-classifiers
[info] Trying to create an Idea module default-d73535
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving org.scalaz#scalaz-core_2.9.1;6.0.3 ...
[info] Excluding folder target
[info] Created /Users/jason/code/scratch/20120225/.idea/IdeaProject.iml
[info] Created /Users/jason/code/scratch/20120225/.idea
[info] Excluding folder /Users/jason/code/scratch/20120225/target
[info] Created /Users/jason/code/scratch/20120225/.idea_modules/default-d73535.iml
[info] Created /Users/jason/code/scratch/20120225/.idea_modules/project.iml

 ~/code/scratch/20120225 grep jar /Users/jason/code/scratch/20120225/.idea/libraries/*.xml
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-library.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$PROJECT_DIR$/lib_managed/docs/org.scala-lang/scala-library/scala-library-2.9.1-javadoc.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scala_lang_scala_library_2_9_1.xml:      <root url="jar://$PROJECT_DIR$/lib_managed/srcs/org.scala-lang/scala-library/scala-library-2.9.1-sources.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$PROJECT_DIR$/lib_managed/jars/org.scalaz/scalaz-core_2.9.1/scalaz-core_2.9.1-6.0.3.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$PROJECT_DIR$/lib_managed/docs/org.scalaz/scalaz-core_2.9.1/scalaz-core_2.9.1-6.0.3-javadoc.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/org_scalaz_scalaz_core_2_9_1_6_0_3.xml:      <root url="jar://$PROJECT_DIR$/lib_managed/srcs/org.scalaz/scalaz-core_2.9.1/scalaz-core_2.9.1-6.0.3-sources.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/scala_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-library.jar!/"></root>
/Users/jason/code/scratch/20120225/.idea/libraries/scala_2_9_1.xml:      <root url="jar://$USER_HOME$/.sbt/boot/scala-2.9.1/lib/scala-compiler.jar!/"></root>

这篇关于如何设置IntelliJ Idea Scala项目来识别本地Ivy2缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆