Gradle FAILURE: Build failed with an exception - Task not found in root project

code2care@mac Desktop % gradle myTask

FAILURE: Build failed with an exception.

* What went wrong:
Task 'myTask' not found in root project 'my-java-project'. Some candidates are: 'tasks'.

* Try:
Run gradle tasks to get a list of available tasks. 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


If you ran into the above error while trying to build your Java code using Gradle, the reason could be one of the following,

  1. Make sure that the task that you are trying to run is available in your build.gradle file.

  2. The build.gradle file maybe missing in your project folder, make sure it is available under the root folder, example: if my-java-project is my project folder, just inside it you must have your build.gradle file.

  3. Did you spell the Gradle build file right: If you created your build script manually make sure its spelled right.
Gradle Build Failed with an exception. Task not found in root project error
Gradle Build Failed with an exception. Task not found in root project error

Solution: The above error was solved when I placed the below build.gradle file in my-java-project folder,

task helloWorld {

 doLast {
  println 'Hello World!'

code2care@mac gradle-examples % gradle helloWorld

> Task :helloWorld
Hello World!

1 actionable task: 1 executed
Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -