IntelliJ Scala无法构建一个简单的项目(SBT可以)

时间:2015-05-26 07:41:52

标签: scala intellij-idea

我在我的Windows 7机器上安装了IntelliJ idea社区版14.1.3。

我创建了一个简单的sbt项目,其中build.sbt文件看起来像

name := "SlickTest"

version := "1.0"

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick" % "3.0.0-RC3",
  "org.slf4j" % "slf4j-nop" % "1.6.4",
  "com.typesafe" % "config" % "1.0.2"

)

现在我写了一个简单的类

import com.typesafe.config.ConfigFactory

object Foo {
  def main(args : Array[String]): Unit = {
    println("foo")
    val conf = ConfigFactory.load()
    val foo = conf.getString("derby.url")
    println(foo)
  }
}

我创建了一个名为" application.conf"的文件。在资源文件夹中。

derby = {
  url = "foo"
}

现在,如果我转到命令行并说sbt clean compile run我可以看到

D:\myapps\Scala\SlickTest>sbt clean compile run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from D:\myapps\Scala\SlickTest\project
[info] Set current project to SlickTest (in build file:/D:/myapps/Scala/SlickTest/)
[success] Total time: 0 s, completed May 26, 2015 2:24:04 AM
[info] Updating {file:/D:/myapps/Scala/SlickTest/}slicktest...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to D:\myapps\Scala\SlickTest\target\scala-2.11\classes...
[success] Total time: 3 s, completed May 26, 2015 2:24:07 AM
[info] Running Foo
foo
foo
[success] Total time: 0 s, completed May 26, 2015 2:24:07 AM

D:\myapps\Scala\SlickTest>

但是当我尝试在Intellij构思中构建相同的项目时,我看到了

Error:scalac: Error: Could not find an output directory for D:\myapps\Scala\SlickTest\src\main\scala-2.11\SlickTest.scala in List((D:\myapps\scala\SlickTest\src\test\resources,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\resources,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\scala-2.11,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\scala,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\java,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\scala-2.11,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\scala,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\java,D:\myapps\scala\SlickTest\target\scala-2.11\classes))
scala.reflect.internal.FatalError: Could not find an output directory for D:\myapps\Scala\SlickTest\src\main\scala-2.11\SlickTest.scala in List((D:\myapps\scala\SlickTest\src\test\resources,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\resources,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\scala-2.11,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\scala,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\test\java,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\scala-2.11,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\scala,D:\myapps\scala\SlickTest\target\scala-2.11\classes), (D:\myapps\scala\SlickTest\src\main\java,D:\myapps\scala\SlickTest\target\scala-2.11\classes))    
    at scala.tools.nsc.settings.MutableSettings$OutputDirs.outputDirFor(MutableSettings.scala:311)    
    at scala.tools.nsc.backend.jvm.BytecodeWriters$class.outputDirectory(BytecodeWriters.scala:26)    
    at scala.tools.nsc.backend.jvm.GenASM.outputDirectory(GenASM.scala:23)    
    at scala.tools.nsc.backend.jvm.BytecodeWriters$class.getFile(BytecodeWriters.scala:41)    
    at scala.tools.nsc.backend.jvm.GenASM.getFile(GenASM.scala:23)    
    at scala.tools.nsc.backend.jvm.GenASM$JBuilder.writeIfNotTooBig(GenASM.scala:531)    
    at scala.tools.nsc.backend.jvm.GenASM$JMirrorBuilder.genMirrorClass(GenASM.scala:2835)    
    at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.emitFor$1(GenASM.scala:193)    
    at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:203)    
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1500)    
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1487)    
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1482)    
    at scala.tools.nsc.Global$Run.compile(Global.scala:1580)    
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:126)    
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:102)    
    at xsbt.CompilerInterface.run(CompilerInterface.scala:27)    
    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:483)    
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102)    
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:48)    
    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:62)
    at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:20)
    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:483)    
    at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

有人知道为什么IntelliB可以在sbt轻松构建时构建同一个项目。

我搜索了几个找不到输出目录的线程,但他们没有帮助我,因为与其他人不同,我的路径或项目名称中没有大小写错误。

1 个答案:

答案 0 :(得分:4)

打开项目设置并使用此项目的输出路径填充输入,如下图所示。enter image description here