Intellij IDEA - 输出路径 ...\project target\idea-classes 与源根目录相交。只有由构建创建的文件才会被清理

问题描述 投票:0回答:3

使用 Intellij IDEA 和 Scala 插件。

当执行

Build
->
Rebuild Project
时,我收到以下 make 警告:

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.

该项目是使用SBT gen-idea插件生成的。

警告中提到的两个输出路径在

Project Structure
->
Modules
->
ProjectName-build
->
Paths
->
Use module compile output path
下设置为项目构建模块的输出路径和测试输出路径。

查看

ProjectName
模块和
ProjectName-build
模块的“源”选项卡,我发现没有任何地方将
ProjectRootFolder\project\target
标记为
Source

scala intellij-idea sbt gen-idea
3个回答
3
投票

这些警告似乎是由于

project
.
文件夹在
Sources
模块中被标记为
ProjectName-build
引起的。

由于使用 IDEA 构建项目时不需要 SBT 构建模块,因此一种解决方案是生成不带该模块的 IDEA 项目:

sbt gen-idea no-sbt-build-module

更多详细信息请参见:https://github.com/mpeltonen/sbt-idea/issues/180

更新

删除构建模块实际上是有问题的,因为 build.scala 文件会显示很多警告,因为所需的库会丢失。

一个解决方案是取消标记

.
project
,使其不再是构建模块的
Sources
,这也很麻烦,因为它需要在每个生成想法之后完成。

更好的解决方案是使用 sbt 来构建项目而不是 make。为了实现这一点,请删除 IDEA 运行配置中的 make before launch 步骤,并添加 SBT

products
步骤。


1
投票

我收到了同样的警告,到目前为止还没有造成任何问题。

this代码来看,他们似乎只是只删除IDE生成的文件,否则他们会想要删除目标目录中的所有内容。他们通过检查那里是否有任何源文件来确保安全:

// 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);
    }
  }
}

0
投票

你可以尝试执行maven的clean命令

© www.soinside.com 2019 - 2024. All rights reserved.