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?
3 Answers
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.
-
3@JackB don't mix up
gradle idea
command line which generates the project andidea
plug-in which is used when IntelliJ IDEA is importing the project, these are not related and produce different project files. Oct 31, 2017 at 14:56 -
8Delegating IDE build/run actions to gradle is much slower though. :( Dec 19, 2017 at 19:31
-
2The whole point of using an IDE with a script like Gradle or Maven was that the IDE could pick up the gradle scripts and would quickly build the project with minimal fuss. But if you have to build the gradle script every time, all your actions become slow. I feel sorry, you are making a very useful tool useless. Oct 9, 2018 at 16:25
-
3You have two output folders now. The script itself will build everything in the build folder. So if you want some taks to generate some java classes using gradle, they will always be generated in the build folder. And the ide in out folder. You cant manually make it source folder as every gradle build will reset your custom settings. Only the explicit source sets are compiled by the ide, the generated sets are not even clickable or traversable. Previously in 2017 at least i could add a fake source as build/classes/... And ide would find it, now it wont any more. It's becoming a mess. Oct 9, 2018 at 23:52
-
2The problem with this is the IntelliJ does not perform resource filtering so running say spring boot with resourceFiltering for yml files your run hen fails as tokens are not replaced by IntelliJ, What fun Nov 15, 2018 at 12:29
File | Project Structure | Project Settings | Modules | Paths tab | Compiler output
Select 'Inherit project compile output path' to continue using /build
for build artifacts
-
4But as soon as you run
gradle build
the build directory will be back with all its duplicates Jul 18, 2017 at 19:14 -
14IntelliJ IDEA is no longer sharing the output with Gradle, please see youtrack.jetbrains.com/issue/IDEA-175172 for details. Jul 18, 2017 at 20:04
-
11@CrazyCoder, thanks for interesting link to youtrack issue. Discussion there suggests (among other things) to try delegating IDEA build/run to Gradle. I had similar problems with duplicate (yet different) structure of
out
directory, but after setting File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Runner => Delegate IDE build/run actions to gradle I got much better results. Maybe not for everyone, but may be the way for many.– virgo47Sep 3, 2017 at 17:04
Here is my understanding:
Basically, this is a work-around for an incompatibility issue between
Gradle build path
andIDEA 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/
andbuild/
) https://youtrack.jetbrains.com/issue/IDEA-189063