This project setup show some issues I encountered with the Intellij IDEA runner. All the issues described here are present on the Intellij 2021.3.1 release (Build #IC-213.6461.79, built on December 28, 2021).
The project rely on code generation (Dagger2).
It is composed of 4 modules:
android
(a simple android module used here to trigger the intellij android plugin)core
(which contains a class that can print the current project version)game
(a java module which relies oncore
to create a jar that print the current project version)chat
(a kotlin module which relies oncore
to create a jar that print the current project version)
When running the game
and chat
main classes using the gradle runner, everything works fine as expected
(classes are generated, compiled, resources are processed and gathered into the classpath).
However, my real project have 5 launch configurations and launching them all at the same time using a compound can take up to 3 minutes
using Gradle when it is about 10 seconds using the Intellij IDEA runner.
Unfortunately, when I switch to the Intellij IDEA runner a couple of odd things start appearing.
I understand that the IDEA runner do miss some gradle feature and I am fine with that but its build actions are inconsistents
thus it does not allow me to have a nice workaround.
Below I described 4 test cases that summarize the issues encountered.
android plugin
enabledandroid.tasks.runner.restricted
set totrue
(This option is available via the Intellij registry panel)Run/Debug
option set toIntellij IDEA
- Launching the main class from the game module (Java module)
- Does not perform any gradle tasks
- Generates the dagger classes (.java) directly into the module in the module under
src/main/generated
- Compiles the classes into the
build/classes/java/main
folder - Does not copy the module resources into the default Intellij
out
build folder nor into the gradlebuild
folder
- Does see the generated dagger classes from the
src/main/generated
folder
- Includes the
build/classes/java/main
folder in the classpath for running the app - It does not include the
build/resources/main
folder in the classpath for running the app - However, if an
out/production/resources
folder is present when the main is launched, it adds it into the classpath as well
- Why Intellij do not copy the module resources folder into the
out
folder automatically?
android plugin
enabledandroid.tasks.runner.restricted
set totrue
(This option is available via the Intellij registry panel)Run/Debug
option set toIntellij IDEA
- Launching the main class from the chat module (Kotlin module)
- Does not perform any gradle tasks
- Does not generate any dagger classes (thus creating compilations errors)
If I manually generate the dagger classes file using gradle kaptKotlin task, it also:
- Compiles all classes into the
build/classes/java/main
folder - Does not copy the module resources into the default Intellij
out
build folder nor into the gradlebuild
folder
- Does see the generated dagger classes from the
build/generated/source/kapt/main
folder
- Includes the
build/classes/java/main
folder in the classpath for running the app - Includes the
build/tmp/kapt3/classes/main
folder in the classpath for running the app (empty folder) - It does not include the
build/resources/main
folder in the classpath for running the app - However, if an
out/production/resources
folder is present when the main is launched, it adds it into the classpath as well
- Why Intellij do not generate the kotlin dagger classes?
- Why Intellij do not copy the module resources folder into the
out
folder automatically? - Is it expected that Intellij copy the Kotlin classes into the
build/classes/java/main
instead ofbuild/classes/kotlin/main
? - Why the folder
build\tmp\kapt3\classes\main
is added to the classpath?
The cases 3&4 are the same as 1&2 with the android.task.runner.restricted
set to false
The behaviors are much different.
android plugin
enabledandroid.tasks.runner.restricted
set tofalse
(This option is available via the Intellij registry panel)Run/Debug
option set toIntellij IDEA
- Launching the main class from the game module (Java module)
- Generate the dagger classes (.java) directly into the
build/generated/sources/annotationProcessor/java/main
folder - Trigger gradle
compileJava
, andtestClasses
tasks (which triggers theprocessResources
task as well) - Compile the classes into the "build/classes/java/main" folder
- Does not copy the module resources into the default Intellij
out
build folder
- Does not see the generated dagger classes from the
build/generated/sources/annotationProcessor/java/main
folder
- Include the
build/classes/java/main
folder in the classpath for running the app - It does not include the
build/resources/main
folder in the classpath for running the app - However, if an
out/production/resources
folder is present when the main is launched, it adds it into the classpath as well
I assume in this case the gradle tasks are run because of the android plugin runner and it should not be the case.
Why Intellij does not copy the module resources into the out
folder?
Why intellij does not use the build/resources/main
folder into the classpath to run the app?
Why the editor does not see the generated dagger classes from the build/generated/sources/annotationProcessor/java/main
folder?
android plugin
enabledandroid.tasks.runner.restricted
set tofalse
(This option is available via the Intellij registry panel)Run/Debug
option set toIntellij IDEA
- Launching the main class from the chat module (Kotlin module)
- Generate the dagger classes (.java) directly into the
build/generated/source/kapt/main
folder - Trigger gradle
compileJava
, andtestClasses
tasks (which triggers theprocessResources
task as well) - It compile the java classes (dagger generated) into the
build/classes/java/main
folder It compile the kotlin classes (module classes) into thebuild/classes/kotlin/main
folder - Does not copy the module resources into the default Intellij
out
build folder
- Does see the generated dagger classes from the
build/generated/source/kapt/main
folder
- Include the
build/classes/java/main
folder in the classpath for running the app - It does not include the
build/resources/main
folder in the classpath for running the app - It does not include the
build/classes/kotlin/main
folder in the classpath for running the app (thus making the app fail) - However, if an
out/production/resources
folder is present when the main is launched, it adds it into the classpath as well
I assume in this case the gradle task are run because of the android plugin runner and it should not be the case.
Why Intellij does not copy the module resources into the out
folder?
Why intellij does not use the build/resources/main
folder into the classpath to run the app?
Why intellij does not include the build/classes/kotlin/main
folder in the classpath for running the app