What gradle task is intellij running on sync?
# gradle
b
What gradle task is intellij running on sync?
n
none
b
Is there a way to hook up an action via geadle to do something on sync?
n
im not sure. what are you looking to do?
b
Assume simple println on each sync
n
You can just add the println to all the builds.
b
Tasks you mean? That would be too spammy.
j
Maybe only in the root settings or build files?
v
What is it that you actually want to achieve?
b
I'd like to setup some githooks on intellij sync
v
Maybe what you are after is the
idea-ext
gradle plugin.
With that you can also define afterSync actions
So that IntelliJ always invokes the given tasks after a sync (including the initial sync iirc)
b
Hmm, looks interesting. I'm still curious to know what cmd Intellij invokes on sync (as clearly gradle is cooking something each time)
v
It asks over the tooling api for the model for idea
j
If you don't use intellij and you run only gradle commands, then the after sync is not going to happen, no?
v
No, but that was the question, how to do some action when IJ syncs the project
j
Yeah, I know, I have a "related" question. I can just add plain code to settings or build gradle files and every time I sync with the ide or run gradlew build, that code will run (for example writing a file with the pre commit config in the .git folder). Can this break some gradle cache like configuration one?
v
You need to replace "every time I run gradlew" by "every time configuration phase is executed". So it will not be executed of the configuration cache is reused. But I don't think this would disturb the configuration cache feature. If you need to do it in each build even if configuration cache is reused, you need a shared build service, that you register as operation completion listener and that implements auto closeable. That should ensure it is invoked on each build.
👍 1
m
This question of doing a sync from the command line comes up relatively often. Would it be possible to have something that "replicates" what intelliJ is doing and maybe outputs that as a report for purely debugging/introspection purposes?
👍 2
n
Its not a good idea to add an action to every sync. Its better just to have the task run and tell developers to run it to set them up. That way you aren't doing extra work on every sync phase.
👍 2
v
Copy code
This question of doing a sync from the command line comes up relatively often. Would it be possible to have something that "replicates" what intelliJ is doing and maybe outputs that as a report for purely debugging/introspection purposes?
Actually most often it is not "running sync from command line", but more recognizing a sync done from IDE. To do a "sync from command line" you can probably simply use the tooling API and call what the ide calls.
b
@Vampire are there any docs i could read on that tooling API you've mentioned? Never heard of it before.
m
@Vampire agreed. I still think there is some value in making that process (of using the tooling API and call what the ide calls) easier for the community to get better troubleshooting tools as well as give more precise information when filing bugs. Ideally, idea would depend on an intermediate dependency like
idea-gradle-model.jar
that would expose all the Gradle model used by idea. That model could then either be used by Idea itself at runtime or by a debug Gradle plugin (maybe
idea-model-debug
) that adds a task that serializes it to a
idea-model-report.json
. Users that would like to debug Idea could apply the plugin and "emulate" what Idea is doing. This is certainly a large undertaking and certainly more on jetbrains side but seems like that would have some value.
@Big Chungus this is the doc about the tooling API: https://docs.gradle.org/current/userguide/third_party_integration.html#embedding. In a nutshell, you create a
ProjectConnection
that allows you to retrieve the internal Gradle models using something like getModel.
👍 1
v
Btw. actually you can detect an IJ sync if you really want by checking the
idea.sync.active
system property.