Java 不支持不必要地替换不存在的任务

Java 不支持不必要地替换不存在的任务,java,gradle,compiler-errors,compilation,Java,Gradle,Compiler Errors,Compilation,我得到了以下错误: 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 ':

我得到了以下错误:

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()'.

清除缓存并再次启动应用程序。这可能发生在您最近升级gradle时。 如果您使用intellij idea,请选择文件->使缓存无效并重新启动


如果您正在使用gradle,请删除.gradle文件夹,然后再次运行gradle。

引用gradle项目GitHub问题的答案:

这是由于Gradle 6.0中的一个长期不推荐的行为导致的。不幸的是,我们不打算恢复旧的行为,但我们将与JetBrains合作,使这种事情在不需要IDEA方面进行特殊处理的情况下工作

IntelliJ IDEA 2019.3(现在处于测试版)中已经修复了这一问题。如果您可以升级到2019.3 EAP或beta版,那么应该可以在那里使用


将IntelliJ更新至最新稳定版本以修复此问题。在撰写本文时,2019.3.1是IntelliJ IDEA的最新稳定版本。

对于我来说,我通过使用本地gradle分发设置而不是默认的gradle包装解决了这个问题。此设置位于Buil、Execution、Deployment>gradle部分。

如果您使用Intellij idea,这可能会有帮助:
设置->构建、执行、部署->渐变->使用IntelliJ IDEA构建和运行我尝试了所有方法,只有这个家伙为我工作

解决办法非常简单。与其使用gradle构建和运行,不如选择Intellij构建和运行

  • 将build and run using的值从gradle更改为Intellij:

  • 它应该是这样的:


  • 回到gradle-5.6.4帮助我克服了这个问题。将Intellij更新到最新版本为我解决了这个问题。截至2020年6月,我在Intellij Idea 2019.2.4版本中遇到了这个问题,但在更新到最新版本(2020.1.2)后,这个问题得到了解决resolved@PrasanthRajendran是的,更新到2019.3.1或更高版本应能解决问题,除非将来引入回归。在使缓存无效并重新启动后,它将不起作用欢迎使用Stackoverflow。请使用格式良好的代码,并尝试对您的答案进行良好的描述,以便对其他人有所帮助。请不要使用链接进行回答,因为链接可能会过时。相反,你应该制定一个链接站点的内容概要,并将其放在你的答案中,然后提供一个链接到该站点作为信息的来源。对不起,我的不好。修正了我的错误。谢谢你指出。已添加带有摘要的截图,以供其他人将来参考。恢复了我的否决票,感谢更新答案!:-)我知道这已经很旧了,但我能够解决这个问题的一种方法是转到gradle>wrapper>gradle-wrapper.properties并将distributionUrl更改为使用gradle 6之前的gradle分发。希望这个评论能对将来的人有所帮助。