Unset JDK for a Gradle project

Answered

I need to create a Gradle Java project that doesn't rely on a JDK. Indeed, we have a dependency that implements the necessary standard library classes (but not all, or not entirely, for example, not all methods are available).

The Gradle build itself is not an issue. The problem arises with code autocompletion, which defaults to using JDK classes instead of the Gradle dependency classes.

We've created a plugin that sets the project's JDK to null. The issue is that the Gradle plugin always reinstates a JDK every time the project is reloaded.

What would be the best way to proceed? Is it feasible to create a dummy SDK to be used by our project?

0
3 comments
Official comment

A dummy SDK in IntelliJ indeed can do the trick.
When reloading project, IDEA will try to respect Gradle option idea.module.jdkName (reference) and will look for SDK with matching name. So if the dummy SDK has this name, it will be used.

Hi Nikita,

Thanks for your answer. I've tried to use a dummy SDK and use idea.module.jdkName, but I get this kind of warnings in logs: 2023-11-07 16:45:23,392 [  44736]   WARN - #c.i.o.p.i.j.JdkAuto - Multiple SdkType candidates [JavaSDK, Android SDK, MyDummy SDK]. Proceeding with a first candidate: JavaSDK.

So it looks like it cannot set my SDK by its name and so it uses the first JDK found.

0

Seems like your plugin registers a new `SdkType` extending `JavaSdkType`. I thought about your IDEA plugin registering a new sdk with type `JavaSdkType` and name matching one configured in `idea.module.jdkName`

0

Please sign in to leave a comment.