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

JavaIntellij IdeaGradle

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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

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.

Solution 2 - Java

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

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

Solution 3 - Java

Here is my understanding: > Basically, this is a work-around for an incompatibility issue between > Gradle build path and IDEA output path. > > - the issue is - https://github.com/gradle/gradle/issues/2315 > - the solution is - keep these two directories seperate, therefore you have two (out/ and build/) https://youtrack.jetbrains.com/issue/IDEA-189063

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeterView Question on Stackoverflow
Solution 1 - JavaCrazyCoderView Answer on Stackoverflow
Solution 2 - JavaPeterView Answer on Stackoverflow
Solution 3 - JavaleoView Answer on Stackoverflow