2

Using Intellij IDEA with Scala plugin.

When doing a Build -> Rebuild Project I get the following make warnings:

Output path ProjectRootFolder\project\target\idea-test-classes intersects with a source root. Only files that were created by build will be cleaned.
Output path ProjectRootFolder\project\target\idea-classes intersects with a source root. Only files that were created by build will be cleaned.

The project was generated with SBT gen-idea plugin.

The two output paths mentioned in the warnings are set as output path and test output path for the build module of the project under Project Structure -> Modules -> ProjectName-build -> Paths -> Use module compile output path.

Looking at the Sources tab for both the ProjectName module and ProjectName-build modules I saw that there is no place where ProjectRootFolder\project\target was marked as Source.

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169

2 Answers2

3

It seems the warnings were caused by the fact that the project and . folders were marked as Sources in the ProjectName-build module.

Since the SBT build module is not needed when using IDEA to build the project, one solution would be to generate the IDEA project without that module:

sbt gen-idea no-sbt-build-module

More details here: https://github.com/mpeltonen/sbt-idea/issues/180

UPDATE

Removing the build module is actually problematic since the build.scala file will show a lot of warnings because the required libraries would be missing.

A solution would be to unmark . and project from being Sources of the build module, which is also troublesome since it would need to be done after each gen-idea.

A better solution would be to use sbt to build the project instead of make. To achieve that remove the make before launch step in the IDEA run configuration and add a SBT products step instead.

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • 1
    Latest version of IntelliJ lets you import SBT projects directly without plugin - I just learned it a few days ago. So far it works perfectly well so I might stop using gen-idea plugin. – yǝsʞǝla Mar 02 '14 at 01:35
  • @AlekseyIzmailov: Thanks, that is nice to know. The project imported that way seems to have much better folder types marking but when accessing project structure I'm getting a lot of unused libraries errors. – Răzvan Flavius Panda Mar 02 '14 at 16:26
1

I get the same warning and it didn't cause any problems so far.

Judging by this code it seems that they simply delete only files generated by IDE, otherwise they would want to delete everything in target directory. They are playing safe by checking if there could be any source files there:

// check that output and source roots are not overlapping
final List<File> filesToDelete = new ArrayList<File>();
for (Map.Entry<File, Collection<BuildTarget<?>>> entry : rootsToDelete.entrySet()) {
  context.checkCanceled();
  boolean okToDelete = true;
  final File outputRoot = entry.getKey();
  if (JpsPathUtil.isUnder(allSourceRoots, outputRoot)) {
    okToDelete = false;
  }
  else {
    final Set<File> _outRoot = Collections.singleton(outputRoot);
    for (File srcRoot : allSourceRoots) {
      if (JpsPathUtil.isUnder(_outRoot, srcRoot)) {
        okToDelete = false;
        break;
      }
    }
  }
  if (okToDelete) {
    // do not delete output root itself to avoid lots of unnecessary "roots_changed" events in IDEA
    final File[] children = outputRoot.listFiles();
    if (children != null) {
      filesToDelete.addAll(Arrays.asList(children));
    }
    else if (outputRoot.isFile()) {
      filesToDelete.add(outputRoot);
    }
  }
  else {
    context.processMessage(new CompilerMessage(
      "", BuildMessage.Kind.WARNING, "Output path " + outputRoot.getPath() + " intersects with a source root. Only files that were created by build will be cleaned.")
    );
    // clean only those files we are aware of
    for (BuildTarget<?> target : entry.getValue()) {
      clearOutputFiles(context, target);
    }
  }
}
yǝsʞǝla
  • 16,272
  • 2
  • 44
  • 65