By default, the gradle idea plugin marks the build folder as excluded. How do I include this folder as source folder? (or avoid excluding it, as it appears to be by default...)
In my module build.gradle file I tried with the two following configurations:
idea {
module {
excludeDirs -= file('build/generated')
}
}
and:
idea {
module {
sourceDirs += file('build/generated')
}
}
With those two configurations the folder build/generated always appears as excluded folders in IntelliJ after compilation. In IntelliJ I always have to go in "Project Settings", "Modules" and then in the tab "Sources" to remove the build folder from the excluded folders and let my project run.
From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Project Settings | Modules. Select the necessary module and then open the Sources tab in the right-hand part of the dialog. Click Add Content Root and specify the folder that you want to add as a new content root.
In the Project tool window ( Alt+1 ), right-click the node in which you want to create a new directory and select New | Directory. Alternatively, select the node, press Alt+Insert , and click Directory. Name the new directory and press Enter .
You definitely want the build
directory to be excluded in IntelliJ. Otherwise, indexing will take longer, you'll get duplicates in searches, etc. Since IntelliJ doesn't support including a subdirectory of an excluded directory, my preferred solution is to put generated files into a directory outside build
. For example, you could put them into generated
(relative to the project directory), and configure the clean
task accordingly:
clean {
delete "generated"
}
Another option is to exclude all subdirectories of build
except build/generated
. However, given that the directories to be excluded will need be listed explicitly, this takes more effort, and bears the risk of being fragile. (You don't want this to break every time a plugin/task/etc. adds a new subdirectory.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With