# Idiomatic way to generate source code that works in IDEs automatically without using specific IDE Gradle plugin

**URL:** <https://discuss.gradle.org/t/idiomatic-way-to-generate-source-code-that-works-in-ides-automatically-without-using-specific-ide-gradle-plugin/24705>\
**Category:** Help/Discuss\
**Created:** [November 8, 2017, 11:20pm UTC](https://discuss.gradle.org/t/idiomatic-way-to-generate-source-code-that-works-in-ides-automatically-without-using-specific-ide-gradle-plugin/24705 "2017-11-08T23:20:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkobit](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mkobit/32/7217_2.png) [@mkobit](https://discuss.gradle.org/u/mkobit)\
**Post date:** [November 8, 2017, 11:20pm UTC](https://discuss.gradle.org/t/idiomatic-way-to-generate-source-code-that-works-in-ides-automatically-without-using-specific-ide-gradle-plugin/24705/1 "2017-11-08T23:20:28Z")

</div>

There are a _lot_ of questions out there around source code generation with Gradle. Here are some that I found after a few minutes of searching:

- [Proper strategies for generating sources and compiling generated and non-generated code together?](https://discuss.gradle.org/t/proper-strategies-for-generating-sources-and-compiling-generated-and-non-generated-code-together/7252)
- [How to use gradle with generated sources?](https://discuss.gradle.org/t/how-to-use-gradle-with-generated-sources/9401)
- [How can I compile generated sources?](https://discuss.gradle.org/t/how-can-i-compile-generated-sources/7541)
- [How to add generated sources to compile classpath without adding them to the main sourceSet?](https://discuss.gradle.org/t/how-to-add-generated-sources-to-compile-classpath-without-adding-them-to-the-main-sourceset/5614)
- [How to generate source code during project import?](https://discuss.gradle.org/t/how-to-generate-source-code-during-project-import/21091)
- [How do I get IntelliJ to recognize gradle generated sources dir?](https://discuss.gradle.org/t/how-do-i-get-intellij-to-recognize-gradle-generated-sources-dir/16847)
- [https://stackoverflow.com/questions/28345705/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle](https://stackoverflow.com/questions/28345705/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle)
- [https://github.com/google/protobuf-gradle-plugin/issues/109](https://github.com/google/protobuf-gradle-plugin/issues/109)
- [https://stackoverflow.com/questions/36749015/how-do-i-get-intellij-to-recognize-gradle-generated-sources-dir](https://stackoverflow.com/questions/36749015/how-do-i-get-intellij-to-recognize-gradle-generated-sources-dir)
- [https://stackoverflow.com/questions/5025468/how-to-generate-source-files-and-compile-them-with-gradle](https://stackoverflow.com/questions/5025468/how-to-generate-source-files-and-compile-them-with-gradle)
- [https://stackoverflow.com/questions/35213894/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle-and-intellij](https://stackoverflow.com/questions/35213894/how-can-i-add-a-generated-source-folder-to-my-source-path-in-gradle-and-intellij)

There are a lot of varied answers in here.

What I am currently doing is:

- Add a directory to the `SourceSet`
- Create a task to generate the code into that directory
- Add a task dependency using `getCompileTaskName(String language)` on the generation task

This works well at build time, but doesn’t integrate so well with IDEs right now. In order to see the code, you must first run something like `./gradlew assemble` to generate those classes before importing or using in the IDE.  
What I would like achieve is:

- Sources generated on import in IntelliJ (or other IDEs)
- Sources can be regenerated on plugin upgrade/configuration change
- Up-to-date checking if possible
- Users don’t have to execute Gradle commands on import or change to get newer generated classes
- Users don’t need to use the `idea` Gradle plugin

Is there a newer answer to handle these use cases?

---

<div class="post-metadata">

**Author:** ![mkobit](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mkobit/32/7217_2.png) [@mkobit](https://discuss.gradle.org/u/mkobit)\
**Post date:** [July 24, 2018, 5:33pm UTC](https://discuss.gradle.org/t/idiomatic-way-to-generate-source-code-that-works-in-ides-automatically-without-using-specific-ide-gradle-plugin/24705/2 "2018-07-24T17:33:57Z")

</div>

One possible answer that was brought up to me on the Gradle Slack: [https://github.com/JetBrains/gradle-idea-ext-plugin](https://github.com/JetBrains/gradle-idea-ext-plugin)

Provides hooks to be used during Gradle’s resolution process.
