IntelliJ runs configure project (automatically triggered by changes on build script or by manual button click “reimport” ).
Anyway in the Build Sync window we can see that no task is executed, only configuration phase and all the gradle execution ends with “CONFIGURE SUCCESSFUL”
How to run ONLY this functionality from the command line?
“gradle tasks” may help
gradle tasks
as was suggested will not only do the configuration phase of course, but will execute the tasks
task.
You can skip the execution phase using --dry-run
(or -m
) so that the tasks that would be executed get configured but are then skipped in the execution phase.
But the question is what you want to actually achieve. If you for example want to do from commandline what IntelliJ is doing for the sync, then you cannot, at least not easily. The IDE is doing more than “just configuring”, it gets information about the build like projects, dependencies and so on. It also uses an init script to inject some things into the build it needs for this.
There are two aspects here:
-
Practical: "How to get through the first two Gradle phases initialization and configuration, but skipping execution, at minimal costs.
Minimal costs mean
a) performance (time)
b) output clarity (not wasting console output with task listing etc.) -
Theoretical: Curiosity - how IDE (IntelliJ in that case) uses Gradle API. Do they use some backdoor features, enhance the API …?
I know that the way IDE uses Gradle can be configured in IDE settings (for build, run, tests), version of JVM is configurable and wrappers usage as well… but even having the same settings in IDE I can still see behavior differences of some Gradle plugins comparing IDE run vs build script run from command line.
Thanks for recommending “dry run” for the point 1.
However, according to documentation the “dry run” resolves task dependencies ( at least some of them which can be resolved statically, not in runtime) … anyway, in many cases I do not even need that task resolution, but only basic objects configuration - project, source sets, plugins.
As “dry run” shows which tasks would be executed, this is of course done, yes.
Calculating the task graph is part of the configuration phase.
If you want to save that time, just use a task with no dependencies, so for example a --dry-run
on tasks
task.
Do they use some backdoor features, enhance the API …?
No backdoor. There is the Gradle tooling API that is intended for IDEs or other tools that need to drive other Gradle builds or also get information from them.
IDE runs and commandline runs should usually not behave differently though.
Unless there is really some intentional “if run from IntelliJ” kind of code, but there should be very little plugins that do something like that.