This short blog post talks about why you get this error and how to fix “Unnecessarily replacing a task that does not exist is not supported”.
What is the error and why does it occur
When you attempt to run or debug a method using Gradle and IntelliJ you may encounter the following error.
Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named ‘Example.main()’, but there is no existing task with that name.
This will stop you building any projects until you have resolved this issue.
This has started to occur when using Gradle 6 as they made old deprecated behaviour be logged as an error. The reply relating to this issue from the gradle devs is:
This is coming from a long deprecated behavior that was finally made an error in Gradle 6.0. Unfortunately, we’re not going to restore the old behavior, but we’ll work with JetBrains to make this sort of thing work without requiring special handling on IDEA’s side.