Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala IntelliJ反复忘记目标src_managed是一个源目录_Scala_Intellij Idea - Fatal编程技术网

Scala IntelliJ反复忘记目标src_managed是一个源目录

Scala IntelliJ反复忘记目标src_managed是一个源目录,scala,intellij-idea,Scala,Intellij Idea,我正在使用IntelliJ 2017.1终极版。我正在从事一个scala项目,在这个项目中,我使用SBT生成了一些代码 代码被复制到target/scala-2.11/src_托管文件夹中 一次又一次,我的编译失败了,我看到IntelliJ忘记了src_managed是一个源目录 如果我右键单击src_托管文件夹并说将目录标记为源根目录,则编译成功。但是IntelliJ一次又一次地忘记这是一个源目录,这非常令人恼火。出于某种原因,当您将“main”添加到源路径时,它会在src\u manage

我正在使用IntelliJ 2017.1终极版。我正在从事一个scala项目,在这个项目中,我使用SBT生成了一些代码

代码被复制到target/scala-2.11/src_托管文件夹中

一次又一次,我的编译失败了,我看到IntelliJ忘记了src_managed是一个源目录


如果我右键单击src_托管文件夹并说将目录标记为源根目录,则编译成功。但是IntelliJ一次又一次地忘记这是一个源目录,这非常令人恼火。

出于某种原因,当您将
“main”
添加到源路径时,它会在
src\u managed/main
中创建源,然后Intellj将其选中:

.settings(
  (sourceGenerators in Compile) += (codeGen in Compile),
  (codeGen in Compile) := {
    val r = (runner in Compile).value
    val s = streams.value.log
    // This is [basedir]/target/scala-2.11/src_managed
    val sourcePath = sourceManaged.value
    val classPath = (fullClasspath in Test in `generator`).value.map(_.data)

    // This is [basedir]/target/scala-2.11/src_managed/main
    val fileDir = new File(sourcePath, "main").getAbsoluteFile
    r.run(
     "com.github.integration.CodeGeneratorRunner",
      classPath, Seq(fileDir.getAbsolutePath), s
    )
  )
)
。。。然后intellj把它捡起来


我不知道怎么做,也不知道为什么,但确实如此。SBT是双向的。也许有一些我们不知道的SBT惯例,也许Intellij有一个bug。

偶然发现了这个问题,因为我也遇到了同样的问题。虽然这个问题很老了,但我会用我的解决方案回答其他可能有同样问题的人

将目录添加为build.sbt中的托管源目录:

Compile / managedSourceDirectories += baseDirectory.value / "target/scala-2.13/src_managed"

// or if you have your scala version in a value/variable
lazy val scalaVersion = "2.13.3"
Compile / managedSourceDirectories += baseDirectory.value / s"target/scala-${"""[\d]*[\.][\d]*""".r.findFirstIn(scalaVersion).get}/src_managed"

IntelliJ应该能够遵循SBT构建设置-您是否在SBT()中将该文件夹添加为源根目录?如下所示
unmanagedSourceDirectories in Compile也不确定:)实际上,这可能不是最好的方法(同一节警告不要对生成的代码使用此方法,并指出哪种方法可能更合适)-恐怕就我的SBT知识而言,希望这些链接能有所帮助。我们也有同样的问题,但只有当您重新加载build.sbt时才会发生(此时IDEA生成.iml文件)是的。我发现每次更改build.sbt文件时,都必须将管理的src_标记为源文件。这很烦人。