'Unnecessarily replacing a task that does not exist is not supported
I got the following error:
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\Users\User\AppData\Local\Temp\Console_main__.gradle' line: 18
* What went wrong:
A problem occurred configuring root project 'demo'.
> Could not create task ':Console.main()'.
> Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'Console.main()', but there is no existing task with that name.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 236ms
10:32:59 PM: Task execution finished 'Console.main()'.
Solution 1:[1]
If you are using Intellij idea, this might help: Settings -> Build, Execution, Deployment -> Gradle -> Build and run using: IntelliJ IDEA
Solution 2:[2]
Quoting an answer on a GitHub issue for the Gradle project from November 15th 2019:
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.
This is already fixed in IntelliJ IDEA 2019.3 (in beta now). If you can upgrade to the 2019.3 EAP or beta, this should work there.
Update IntelliJ to the latest stable version to fix this issue. At the time of this writing, 2019.3.1 is the latest stable release of IntelliJ IDEA.
Solution 3:[3]
I tried everything, only this guy's solution worked for me.
The solution is pretty straight forward. Instead of build and run using gradle, choose, build and run using Intellij.
Solution 4:[4]
For me I solved the issue by using local gradle distribution settings instead of default gradle wrapper. This settings is in Buil, Execution, Deployment > gradle section.
Solution 5:[5]
From the link:https://chewett.co.uk/blog/2420/fixing-gradle-error-unnecessarily-replacing-a-task-that-does-not-exist-is-not-supported/
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.
I upgraded from intellij 19.1 to 2021.2.4 and everything got fixed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Viacheslav Plekhanov |
| Solution 2 | Community |
| Solution 3 | |
| Solution 4 | user666 |
| Solution 5 | Ritesh |




