How to run code in a plugin before Gradle initialization?


Hi, I am writing a plugin that manages users' JDKs based on configuration files checked in to the project. My plugin downloads the JDK and sets it as the project SDK when the project is opened.

I would like to be able to run this code before Gradle verifies the JDK, as in some cases the user's project JDK might point to a directory on disk that does not exist, and this fails the Gradle plugin with "Invalid Gradle JDK configuration found"

Is there a way to run code before the Gradle plugin initialises and tries to use the project JDK? I was looking at implementing the "startupActivity" extension, but it seems this is only allowed to bundled plugins. While, "postStartupActivity" gets executed too late.

Thank you!


While there is no such extension point, you can combine `postStartupActivity` (to change the setting) with an implementation of  `org.jetbrains.plugins.gradle.service.execution.GradleExecutionAware` that will patch the JDK path (see `LocalGradleExecutionAware` for example). 


Nice! That seems to have done just what I wanted. Thank you!


Please sign in to leave a comment.