mpeltonen / sbt-idea

A simple-build-tool (sbt) plugin/processor for creating IntelliJ IDEA project files
Other
1.07k stars 153 forks source link

Source generators trigger creation of incorrect source folders #310

Open varju opened 10 years ago

varju commented 10 years ago

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 {
teigen commented 9 years ago

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.