2012-02-25 51 views
10

正如您所知,SBT的新版本(如0.11)旨在維護~/.ivy2/cache中的公共庫緩存,而不是在項目目錄中複製全套依賴關係。但IntelliJ Idea(我使用SBT插件來生成Idea項目)默認似乎忽略了常見的緩存,只能將項目目錄放在項目目錄下(因此,我必須配置SBT以採用這種傳統方式)。如何解決這個問題?如何設置IntelliJ Idea Scala項目來識別本地Ivy2緩存?

Idea插件存儲庫中有一些Ivy插件,但我不知道它們中的哪些(如果有的話)可以解決問題(請注意,我不希望它管理依賴項並下載庫(因爲它是由SBT完成的),但只是尋找緩存中的類)。

回答

7

sbt-idea是指位於sbt所指的位置的庫,默認情況下位於~/.ivy2/cache之下。

這裏是它的外觀我的系統上,用新的項目,SBT 0.11.2和SBT-想法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使用使所有庫的生成本地副本,而不是直接從緩存中引用它們。如果啓用此功能,sbt-idea也將設置IntelliJ類路徑來引用這些路徑。

這裏的幫助:

> 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> 
+0

主要+1,同樣適用於Eclipse或僅是這個的IntelliJ? – virtualeyes 2012-02-25 09:37:27

+0

'no-sbt-classifiers'做什麼? – 2012-02-25 14:10:11

+0

我一直在使用檢索管理的一切工作。上次嘗試避免它會導致Idea看到圖書館的問題。這是想法10雖然,也許它是固定在11 ... – Ivan 2012-02-25 17:38:00

相關問題