Calling a Gradle task when idea refreshes the project

Answered

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"

12 comments
Comment actions Permalink

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 https://www.jetbrains.com/help/idea/2016.2/gradle-tool-window.html#d329225e354

 

0
Comment actions Permalink

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 gradle.properties file for example:

org.jetbrains.idea.gradle.syncTasks=generateAvroJava,foo,bar,:subproject:someTask
2
Comment actions Permalink

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.

0
Comment actions Permalink

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

 

 

0
Comment actions Permalink

My use case is similar to those above.

0
Comment actions Permalink

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

0
Comment actions Permalink

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

0
Comment actions Permalink

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

1
Comment actions Permalink

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

0
Comment actions Permalink

The idea-ext plugin is not usable for this because of https://youtrack.jetbrains.com/issue/IDEA-282322, if you checkout an older commit then IDEA cannot import or build the project anymore.

0

Please sign in to leave a comment.