I tried the same thing by deleting the .gradle directory and restarting but i still got the errors.
https://www.reddit.com/r/Minecraft/comments/ic0ll3/plz_help_so_i_was_trying_to_use_intellij_for/
U may use this link to look at an image to my problem. I am really new to IntelliJ(like i dont even know what gradle is) and i really want to mod but this error is happening and ur edited solution doesnt work for me.