如何在 IntelliJ IDEA 中改变 Ivy 的家

Posted

技术标签:

【中文标题】如何在 IntelliJ IDEA 中改变 Ivy 的家【英文标题】:How to change Ivy home in IntelliJ IDEA 【发布时间】:2017-03-28 11:57:28 【问题描述】:

sbt 的命令行版本更改Ivy 主目录非常简单。您只需将选项-Dsbt.ivy.home=<new ivy home dir> 添加到$SBT_HOME/conf/sbtconf.txt

我想对 IntelliJ IDEA 的 Scala 扩展做同样的事情(我的 C 驱动器上的磁盘空间不足)。因此,我通过以下方式修改了 SBT 设置:File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> BuildTools -> SBT。在 VM 参数 下,我添加了条目 -Dsbt.ivy.home=<new ivy home dir>。这应该与命令行工具中的效果相同。

当我创建一个基于 sbt 的新 Scala 项目(并添加一个打印消息的 Scala 对象)时,一切似乎都运行良好。我可以构建和运行程序。但是在对源代码进行更改并制作项目(Build -> Make Project)两三次之后,我观察到以下错误:

Error:scalac: Error: assertion failed: 
  Precisely this override requires its invoker to hand out a non-null AbstractFile.
     while compiling: D:\Temp\scala\scalatest3\src\main\scala\Main.scala
        during phase: jvm
     library version: version 2.12.0
    compiler version: version 2.12.0
  reconstructed args: -nobootcp -javabootclasspath ; -classpath C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;D:\temp\scala\scalatest3\target\scala-2.12\classes;D:\Bin\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.12.0.jar
  last tree to typer: TypeTree(class ListBuffer)
       tree position: line 4 of D:\Temp\scala\scalatest3\src\main\scala\Main.scala
            tree tpe: scala.collection.mutable.ListBuffer[() => Unit]
              symbol: final class ListBuffer in package mutable
   symbol definition: final class ListBuffer extends AbstractBuffer with Buffer with GenericTraversableTemplate with BufferLike with ReusableBuilder with SeqForwarder with Serializable (a ClassSymbol)
      symbol package: scala.collection.mutable
       symbol owners: class ListBuffer
           call site: constructor Main$delayedInit$body in class Main$delayedInit$body in package <empty>
== Source file context for tree position ==
     1   * Created by P20058 on 14.11.2016.
     2   */
     3 object Main extends App 
     4   println("Hello scalatest")
     5 
     6 
java.lang.AssertionError: assertion failed: 
  Precisely this override requires its invoker to hand out a non-null AbstractFile.
     while compiling: D:\Temp\scala\scalatest3\src\main\scala\Main.scala
        during phase: jvm
     library version: version 2.12.0
    compiler version: version 2.12.0
  reconstructed args: -nobootcp -javabootclasspath ; -classpath C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;D:\temp\scala\scalatest3\target\scala-2.12\classes;D:\Bin\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.12.0.jar

  last tree to typer: TypeTree(class ListBuffer)
       tree position: line 4 of D:\Temp\scala\scalatest3\src\main\scala\Main.scala
            tree tpe: scala.collection.mutable.ListBuffer[() => Unit]
              symbol: final class ListBuffer in package mutable
   symbol definition: final class ListBuffer extends AbstractBuffer with Buffer with GenericTraversableTemplate with BufferLike with ReusableBuilder with SeqForwarder with Serializable (a ClassSymbol)
      symbol package: scala.collection.mutable
       symbol owners: class ListBuffer
           call site: constructor Main$delayedInit$body in class Main$delayedInit$body in package <empty>

== Source file context for tree position ==

     1   * Created by P20058 on 14.11.2016.
     2   */
     3 object Main extends App 
     4   println("Hello scalatest34")
     5 
     6 

    at scala.tools.nsc.backend.jvm.BytecodeWriters$ClassBytecodeWriter.writeClass(BytecodeWriters.scala:120)

    at scala.tools.nsc.backend.jvm.BytecodeWriters$ClassBytecodeWriter.writeClass$(BytecodeWriters.scala:118)

    at scala.tools.nsc.backend.jvm.BytecodeWriters$$anon$4.writeClass(BytecodeWriters.scala:47)

    at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.sendToDisk$1(GenBCode.scala:408)

    at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.drainQ3(GenBCode.scala:427)

    at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.buildAndSendToDisk(GenBCode.scala:387)

    at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.run(GenBCode.scala:350)

    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1404)

    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1389)

    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1384)

    at scala.tools.nsc.Global$Run.compile(Global.scala:1478)

    at xsbt.CachedCompiler0.run(CompilerInterface.scala:115)

    at xsbt.CachedCompiler0.run(CompilerInterface.scala:94)

    at xsbt.CompilerInterface.run(CompilerInterface.scala:22)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)

    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)

    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)

    at org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:29)

    at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:26)

    at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:67)

    at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:24)

    at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

重建项目(Build -> Rebuild Project)有效。但经过一些 make 迭代后,上述错误再次出现。 有什么我想念的想法吗?

【问题讨论】:

你怎么知道这是 ivy 的问题?? 当我删除选项 -Dsbt.ivy.home=&lt;new ivy home dir&gt; 时,我不再收到构建错误。我认为这是 IntellJ Scala 插件的问题,因为从命令行使用 sbt 效果很好。 【参考方案1】:

检查库,就我而言,我使用了 2 个不同版本的测试库

【讨论】:

以上是关于如何在 IntelliJ IDEA 中改变 Ivy 的家的主要内容,如果未能解决你的问题,请参考以下文章

在 .ivy2 文件中找不到在线依赖,Intellij Idea 也没有找到

[至逝去的一年]修改IntelliJ IDEA修改系统缓存目录,修改sbt的.sbt和.ivy2

在 IntelliJ/Grails 中更改 Ivy 缓存位置

Intellij 在运行 Ivy Project 时无法找到类

如何将 SBT 类附加到 Intellij Idea?

intellij idea15的golang插件怎么配置