Skip to content

aSemy/intellij-gradle-init-plugin

Repository files navigation

intellij-gradle-init-plugin

Proposal for improving IntelliJ compatibility with Gradle incremental tasks

https://youtrack.jetbrains.com/issue/IDEA-240111

Quickstart

  1. Install this project

    cd $MyGitProjectsDir
    git clone git@github.com:aSemy/intellij-gradle-init-plugin.git
    cd intellij-gradle-init-plugin
    ./gradlew publishToMavenLocal
  2. 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

What's wrong?

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.

Where is it wrong?

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.

What's the proposal?

  1. 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.)

  2. IntelliJ will apply the new plugin in addTestListener.init.gradle

  3. 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.

  4. The init script plugin will register an additional task, IJTestEventLoggerTask, that will collect all of those files.

  5. 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.

About

Proposal for improving IntelliJ compatibility with Gradle incremental tasks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published