IntelliJ not recognizing a generated sources folder: how to fix it
Codemia Knowledge Hub ·
If IntelliJ IDEA ignores your generated sources folder, mark it as a source folder (Mark Directory as > Generated Sources Root in Project Structure), make sure Maven or Gradle writes the generated code to that location, and then reload and rebuild the project. If references are still unresolved, reimport the project or invalidate caches.
Generated sources are files produced by tools such as the Maven build or annotation processors. Common reasons for using them:
- Code generation: JPA annotation processors or
AutoValuegenerate code to reduce boilerplate. - Testing: test suite configurations can generate mock classes.
- Resource bundling: build tools package multiple resources together.
When the IDE is not configured for them, you get unresolved references or missing classes.
Why IntelliJ misses generated sources
- Incorrect configuration: IntelliJ does not recognize some folders as source directories if the project configuration is wrong.
- Build differences: the build may succeed on the command line but not in the IDE.
- Indexing problems: IntelliJ may not index the generated files, which breaks autocompletion and analysis.
Configuring IntelliJ to use generated sources
Step 1: Mark the folder
Tell IntelliJ that the folder contains source files:
- Open Project Structure:
- Go to
File > Project Structure.
- Mark the directory:
- Open
Modulesand select the module that contains the generated sources. - In the
Sourcestab, find the generated folder in the directory tree. - Right-click it and select
Mark Directory as > Generated Sources Root.
Step 2: Configure the build tool
With Maven or Gradle, generate sources into a location IntelliJ recognizes:
- Maven:
- Configure the plugin correctly in
pom.xml, for example:
- Gradle:
- Add the generated sources path in
build.gradle:
Step 3: Refresh the IDE
Force IntelliJ to pick up the new sources:
- Run
Build > Rebuild Project. - Right-click
pom.xmlorbuild.gradleand selectReload.
If the sources are still not detected
- Reimport the project: a full reimport as a Maven or Gradle project sometimes fixes it.
- Invalidate caches: go to
File > Invalidate Caches / Restart…and selectInvalidate and Restart. - Check output paths: make sure the build's output path matches the structure IntelliJ expects.
- Read the error messages: the IDE's
Event LogorBuild Outputgives detailed information about specific errors.
| Issue/Task | Solution/Configuration |
| Recognizing Generated Sources | Mark Directory as Generated Sources Root in Project Structure. |
| Maven Configuration | Add <generatedSourcesDirectory> in pom.xml. |
| Gradle Configuration | Modify sourceSets.main.java.srcDirs in build.gradle. |
| IntelliJ Not Recognizing Changes | Rebuild Project, Reload Maven/Gradle, or Reimport Project. |
| Unresolved References or Compilation | Check for correct folder marking and plugin errors in the build tool. |
| IDE Indexing Issues | Invalidate Caches and Restart IntelliJ, then Rebuild Project. |
Related reading
- Unable to use Spring Property Placeholders in logback.xml
- Unable to use sudo commands within Docker, bash sudo command not found is displayed
- unable to use Trained Tensorflow model
- Unable to verify secret hash for client in Amazon Cognito Userpools
- Unauthorized in spring boot admin
- Unbalanced calls to begin/end appearance transitions for FirstViewController 0x2a2c00
- Unbalanced calls to begin/end appearance transitions for UITabBarController 0x197870
- UnboundLocalError local variable 'batch_outputs' referenced before assignment
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.