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?
Building with Intellij 2017.2 /out directory duplicates files in /build directory
Asked Answered
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.
@Unlucky don't mix up
gradle idea
command line which generates the project and idea
plug-in which is used when IntelliJ IDEA is importing the project, these are not related and produce different project files. –
Geotaxis Delegating IDE build/run actions to gradle is much slower though. :( –
Vin
The 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. –
Killing
@Killing you don't have to delegate the build to Gradle, it's just one of the options. By default the build is performed by IntelliJ IDEA and is usually faster than Gradle. –
Geotaxis
You 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. –
Killing
The 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 –
Harangue
@Harangue In your case, I think
Delegate IDE build/run actions to gradle.
is the best option. –
Quadrangular File | Project Structure | Project Settings | Modules | Paths tab | Compiler output
Select 'Inherit project compile output path' to continue using /build
for build artifacts
But as soon as you run
gradle build
the build directory will be back with all its duplicates –
Algebraic IntelliJ IDEA is no longer sharing the output with Gradle, please see youtrack.jetbrains.com/issue/IDEA-175172 for details. –
Geotaxis
@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. –
Patrilineal 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
© 2022 - 2024 — McMap. All rights reserved.
idea
plugin. Which is it? #42500117 – Unlucky