Failed to apply plugin Intellij Gradle

 Failed to apply plugin in Intellij Gradle is caused by wrong Java version being used in Gradle. To fix it, go to Settings -> Build, Execution, Deployment -> Build Tools -> Gradle, find Gradle section, and select the correct Gradle JVM version. The version of JVM used should be compatible with the version of Gradle you are using. 


If all still can't work, try the following:

- Invalidate cache (Go to File -> Invalidate Cache)

- Delete the global .gradle folder (Located in your Users folder), as well as your project .gradle folder, and run ./gradlew.bat --refresh-dependencies

- Ensure the JAVA_HOME and PATH is pointing to the right JDK version. For my case, my project is using Java 11, so the values should reflect. 

JAVA_HOME = C:\Program Files\Java\jdk-11.0.8

PATH=C:\Program Files\Java\jdk-11.0.8\bin

Note: Also, please make sure that the \bin is added at the back of the path. If you have multiple Java version installed, please make sure the path of Java version that your project is using is on top of all other Java version, for example, the red box shows that the jdk version my project is using.


- Ensure that the Intellij is using the right Java version, since Intellij uses that to compile our Java code.

Go to File > Project Structure > Project (Set SDK to the Java version your project is running)

You also need to make sure your project is using the right language level as well

Go to File > Project Structure > Modules (Set SDK to the Project Default)

If you haven't add any SDK, go to
Go to File > Project Structure > SDKs (Under Platform Settings), then, add the SDK that matches your project.


Bonus tip:
If you want to know what gradle version your project is on, and if your project has gradlew.bat, you go do ./gradlew.bat --version. Sometimes, the JDK used is wrong, that's because when the project was initialized, the current Java version being used on our computer is wrong. So in order to fix that, we can change the JDK being used by Gradle by going here




and note, if you don't see the version being changed, that's because the Gradle Daemon is being ran. So you need to shut that down first, before the change can be reflected. This can be done by restarting your Intellij.

Also, if you still can't run any gradle command in Intellij, try running a gradle command using the prompt in Intellij, for example, going to Terminal and type ./gradlew.bat build

If it works, and you prefer to build your project using Intellij Gradle, then try to above solution that was listed.  


Comments

Popular posts from this blog

Support for the experimental syntax 'decorators' isn't currently enabled (5:3):

How to add environment variables into Heroku container

Running CQL scripts in Cassandra