sbt-idea icon indicating copy to clipboard operation
sbt-idea copied to clipboard

Source generators trigger creation of incorrect source folders

Open varju opened this issue 11 years ago • 1 comments

Using either 1.6.0 or 1.7.0-SNAPSHOT, the presence of source generators causes extra sourceFolder entries to be added to the module. A simple example that demonstrates this issue:

import sbt._
import Keys._

object ApplicationBuild extends Build {
  val main = Project("foo", file(".")).settings(

    sourceGenerators in Compile += Def.task {
      val file1 = (sourceManaged in Compile).value / "one" / "Test.java"
      IO.write(file1, """
package one;
class Test {}
""")

      val file2 = (sourceManaged in Compile).value / "two" / "Test.java"
      IO.write(file2, """
package two;
class Test {}
""")

      Seq(file1, file2)
    }.taskValue
  )
}

This leads to a module file containing extra src_managed/main/one and src_managed/main/two source folders:

<sourceFolder url="file://$MODULE_DIR$/../target/scala-2.10/src_managed/main/one" isTestSource="false"/>
<sourceFolder url="file://$MODULE_DIR$/../target/scala-2.10/src_managed/main/two" isTestSource="false"/>
<sourceFolder url="file://$MODULE_DIR$/../target/scala-2.10/src_managed/main" isTestSource="false"/>

In the real world, this is causing problems with Play 2.3.1, leading to errors like this when compiling from IntelliJ:

Error:(7, 14) routes is already defined as object routes
public class routes {

varju avatar Jul 05 '14 04:07 varju

I was hit by this bug too and have a potential fix here https://github.com/teigen/sbt-idea/tree/sbt-0.13-source-generators

There are two obvious ways to solve this by either using sourceManaged as sources or use managedSources as sources. Having both leads nesting of source directories which causes this error.

My fix uses managedSources and ignores any sourceManaged directories which are subfolders of managedSources.

teigen avatar Aug 05 '14 11:08 teigen