Java 使用 Intellij 2017.2 构建 /out 目录会复制 /build 目录中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45174989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:51:48  来源:igfitidea点击:

Building with Intellij 2017.2 /out directory duplicates files in /build directory

javaintellij-ideagradle

提问by Peter

After updating to Intellij 2017.2, building my project creates an /outdirectory that contains generated source files and resource files. These files duplicate files that are already contained in /buildand result in duplicate classcompiler errors for the generated classes. Any ideas on a fix I need in Gradle or IntelliJ?

更新到 Intellij 2017.2 后,构建我的项目会创建一个/out包含生成的源文件和资源文件的目录。这些文件复制了已包含在生成的类中的文件,/build并导致duplicate class编译器错误。关于我需要在 Gradle 或 IntelliJ 中修复的任何想法?

回答by Peter

File | Project Structure | Project Settings | Modules | Paths tab | Compiler output

档案 | 项目结构 | 项目设置 | 模块 | 路径选项卡 | 编译器输出

Select 'Inherit project compile output path' to continue using /buildfor build artifacts

选择“继承项目编译输出路径”以继续/build用于构建工件

回答by CrazyCoder

IntelliJ IDEA is no longer sharing the output with Gradle, please see this ticket for details.

IntelliJ IDEA 不再与 Gradle 共享输出,有关详细信息,请参阅此票证

You can either override it via the following configuration:

您可以通过以下配置覆盖它:

allprojects {
 apply plugin: 'idea'
 idea {
   module {
     outputDir file('build/classes/main')
     testOutputDir file('build/classes/test')
   }
 }
 if(project.convention.findPlugin(JavaPluginConvention)) {
   // Change the output directory for the main and test source sets back to the old path
   sourceSets.main.output.classesDir = new File(buildDir, "classes/main")
   sourceSets.test.output.classesDir = new File(buildDir, "classes/test")
 }
}

or delegate the build to Gradle: File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Runner => Delegate IDE build/run actions to gradle.

或将构建委托给 Gradle:文件 | 设置 | 构建、执行、部署 | 构建工具 | 摇篮 | Runner => 将 IDE 构建/运行操作委托给 gradle。

回答by leo

Here is my understanding:

以下是我的理解:

Basically, this is a work-around for an incompatibility issue between Gradle build pathand IDEA output path.

基本上,这是解决Gradle build path和之间不兼容问题的解决方法 IDEA output path