Calling a Gradle task when idea refreshes the project


I use the avro plugin and i would like to automatically run "generateAvroJava" when idea reloads the project.

is it documented somewhere what gradle tasks idea calls when it refreshes the gradle project? Then i could just make that task depend on "generateAvroJava"


I'd really like to see IDEA support running a task without having to do that through IDEA. The gradle file should be the "source of truth" and I need to be able to generate a new project without everybody having to know that you must then run a specific task to get everything up and running.

Wouldn't it be possible for IDEA to read a pre-determined property that would contain a list of tasks to run when syncing?

So you could put the following into your file for example:


Please check this example. See also this thread for some more information on Kotlin DSL configurations.


IDEA doesn't call gradle tasks during project refresh. It uses gradle tooling api to get project information.

However you can configure it in IDEA. Open gradle tool window, find the task and using context menu enable "execution after and/or before Sync".

See details at



Similar use case here. Previously used "gradlew idea" to update the IntelliJ project model. But that doesn't work with the .idea directory or the linking to Gradle and requires an IDE restart every time, I could hack the XML directly to add, say, a new run configuration with "loose" Groovy that runs as part of the project figuring itself out, but who knows how that might interact with IntelliJ itself updating its files at the same time.


another easy solution would be to have a virtual gradle task that idea calls

lets say that task is called ideaImport then i can just do 

   ideaImport.dependsOn myTask




My use case is similar to those above.


Jendrik How can you do it? Can you show/link an example?


From Kotlin `idea.project` does not have property `settings`! How do you call it from Kotlin?


I knew it was some evil Groovy black magic! Thank you for the hint :)


The idea-ext plugin is not usable for this because of, if you checkout an older commit then IDEA cannot import or build the project anymore.


Please sign in to leave a comment.