javagradleintellij-ideamulti-projecthotswap

IntelliJ Gradle HotSwap building unrelated modules


I am having trouble getting Gradle HotSwap to work reasonably with IntelliJ IDEA.

We have a Java setup which consists of some basic modules, then some country variants that use these basic modules and then even country variants of the GUI.

The structure looks like this:

Root
+--- buildSrc
|    \--- [Some custom precompiled groovy script plugins]
+--- CoreModules
|    \--- [Some modules]
+--- CountryVariants
|    \--- [A module for each country variant]
+--- GuiCountryVariants
|    \--- [A module for each special country GUI variant] 
\--- build.gradle (to be able to run tests for all modules at once)

Which means, we always build and run a specific country. For example, here are the dependencies for the GUI specific runnable CH country variant:

runtimeClasspath - Runtime classpath of source set 'main'.
+--- project :CoreModuleG
|    \--- project :GUICore
|         +--- project :CoreModuleB
|         |    \--- project :CoreModuleC
|         |         \--- project :CoreModuleP
|         |              \--- project :CoreModuleE
|         \--- project :GUICoreModuleG
+--- project :CountryVariantCH
|    \--- project :CoreModuleB (*)
\--- project :GUICore (*)

And by contrast, country variant US has:

runtimeClasspath - Runtime classpath of source set 'main'.
+--- project :CoreModuleB
|    \--- project :CoreModuleC
|         \--- project :CoreModuleP
|              \--- project :CoreModuleE
\--- project :CoreModuleG
     \--- project :GUICore
          +--- project :CoreModuleB (*)
          \--- project :GUICoreModuleG

Now, if I start my country variant for CH with a Gradle JavaExec task, it will of course only compile all modules needed for CH, and it will for example not compile country variant US, as expected. The following is a (shortened) excerpt of the startup:

Gradle Daemon started in 2 s 367 ms
> Task :buildSrc:jar UP-TO-DATE
> Task :GuiVariantCH:processResources UP-TO-DATE
> Task :CoreModuleE:jar SKIPPED
> Task :GUICoreModuleG:jar
> Task :CoreModuleP:jar
> Task :CoreModuleC:jar
> Task :GUICore:jar
> Task :CoreModuleG:jar
> Task :CountryVariantCH:jar
> Task :CoreModuleB:jar
> Task :GUIVariantCH:classes
Connected to the target VM, address: 'localhost:56923', transport: 'socket'
> Task :GUIVariantCH:run

But if I then change a class and use "Run > Debugging Actions > Reload Changed Classes" it builds every single module, including all 24 country variants:

11:03:47: Executing ':classes :testClasses [list of all core modules for tasks :classes and :testClasses] [list of all country variant modules for tasks :classes and :testClasses] [list of all GUI country variant modules for tasks :classes and :testClasses]'...

[long list of executions of all :classes and :testClasses tasks]

> Task :CountryVariantZA:classes
> Task :CountryVariantZA:compileTestJava UP-TO-DATE
> Task :CountryVariantZA:testClasses UP-TO-DATE
> Task :GUICountryVariantCH:classes
> Task :GUICountryVariantCH:compileTestJava NO-SOURCE
> Task :GUICountryVariantCH:testClasses UP-TO-DATE

BUILD SUCCESSFUL in 17s

But since I'm running the :GUICountryVariantCH:run task, I would expect that only :GUICountryVariantCH:classes and :GUICountryVariantCH:testClasses tasks are run.

Of course, if I previously compiled all country variants, it is faster than 17 seconds. But it still is executing tasks it shouldn't and thus takes longer than needed.

So, is this caused by a wrong Gradle configuration, a wrong IntelliJ configuration (IntelliJ IDEA 2023.2.2 (Community Edition)) or is this an actual IntelliJ bug?

Has anybody had success with hot swap in a similar situation?

I searched far and wide but nobody seems to have this specific problem.

What I found is this plugin which lets you hotswap a single file, so I could use this plugin or of course "Compile and reload file" in the context menu within a file.

But I still feel hotswap should be able to work by not invoking :classes but rather :specificModuleStarted:classes. Because if you changed multiple files, reloading just this one particular file is not what you want.


Solution

  • Seems to be a known issue IDEA-304595.

    Make sure to upvote it to raise its' priority for the developers!