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?
- How to use gradle with generated sources?
- How can I compile generated sources?
- How to add generated sources to compile classpath without adding them to the main sourceSet?
- How to generate source code during project import?
- How do I get IntelliJ to recognize gradle generated sources dir?
There are a lot of varied answers in here.
What I am currently doing is:
- Add a directory to the
- 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
Is there a newer answer to handle these use cases?