Proposal for improving IntelliJ compatibility with Gradle incremental tasks
https://youtrack.jetbrains.com/issue/IDEA-240111
-
Install this project
cd $MyGitProjectsDir git clone git@github.com:aSemy/intellij-gradle-init-plugin.git cd intellij-gradle-init-plugin ./gradlew publishToMavenLocal
-
Run the updated IntelliJ version that uses the plugin
cd $IntelliJCommunityRepo git remote add forks/aSemy git@github.com:aSemy/intellij-community.git git fetch forks/aSemy git checkout forks/aSemy/fix/gradle-incremental-test-tasks-2 # run IDEA
IntelliJ breaks a Gradle feature for avoiding re-running tasks.
Fixing this is really important. It would have a huge impact on users, as their workflow would become faster.
Additionally, the power requirements of repeatedly re-running the same tests would be avoided, helping reduce energy usage worldwide.
When running Gradle using IntelliJ, IntelliJ injects a init.gradle
init
script, testFilterInit.gradle
. This file does many things, including adding this code:
taskGraph.allTasks.each { Task task ->
if (task instanceof Test || (abstractTestTaskClass != null && abstractTestTaskClass.isAssignableFrom(task.class))) {
task.outputs.upToDateWhen { false } // <- here's the problem!
}
}
This breaks Gradle up-to-date checks for all test tasks! This forces all tests tasks to run, even if nothing has changed. This is very wasteful (Gradle recommends against it) and can hugely increase the amount of time spent running tests.
-
Migrate from a Groovy init script, to an Init Script Plugin -
IntellijGradleInitPlugin
.This makes the change much more modular, easier to test and debug, and can be written in Kotlin.
(Extra bonus: the init script plugin can be updated independently of an IntelliJ release - meaning bug fixes can be released faster.)
-
IntelliJ will apply the new plugin in
addTestListener.init.gradle
-
When the test tasks run, they'll log the IJLog XML to stdout as normal. Additionally, they'll print the XML messages to file, and register that file as a task output.
-
The init script plugin will register an additional task,
IJTestEventLoggerTask
, that will collect all of those files. -
IJTestEventLoggerTask
will determine if the test tasks have already run, and if they haven't (because they're up-to-date), will print them to stdout.