Fixing Gradle error Unnecessarily replacing a task that does not exist is not supported.

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.

big-guy https://github.com/gradle/gradle/issues/11371

Fixing this error

This error relates to using Gradle 6 with IntelliJ 2019.2 or older. This means to fix the issue you just need to upgrade to IntelliJ 2019.3 or newer.

If this isn’t possible you are able to downgrade gradle to the latest version 5 distribution. This should also resolve the issue.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.