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 https://help.gradle.org
BUILD FAILED in 318ms
If you ran into the above error while trying to build your Java code using Gradle, the reason could be one of the following,
- Make sure that the task that you are trying to run is available in your build.gradle file.
- 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.
- 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
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!'
}
}
Output:
code2care@mac gradle-examples % gradle helloWorld
> Task :helloWorld
Hello World!
BUILD SUCCESSFUL in 606ms
1 actionable task: 1 executed
More Posts related to Gradle,
- Task is ambiguous in root project gradle-examples. Candidates are: myTask1, myTask2
- How to create Gradle Multi-Project in IntelliJ
- Find installed Gradle version command
- Adding Jackson dependency to Java Gradle Project
- Gradle FAILURE: Build failed with an exception - Task not found in root project
- Create a Gradle Java Project in VS Code
- Generate Project Dependency tree using Gradle Command
- Fix: Spring Boot + IntelliJ + Gradle : Unsupported class file major version 64 Error
- Fix: Unsupported Java. Your build is currently configured to use Java 17.0.5 and Gradle 7.1.
- Run IntelliJ Java main method without Gradle build
- Fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle
- Installing Gradle on macOS - Gradle Tutorial
- Fix: Invalid Gradle JDK configuration found. Could not find the required JavaSDK
- How to Clear Gradle Cache on Mac
- How to run Gradle build in offline mode
- Install Gradle VS Code for Java Projects
- How to add maven central repository in build.gradle
More Posts:
- How to Print to stderr in Python - Python
- Java: The value of the local variable string is not used - Java
- How to Change Java JDK Version in IntelliJ IDE - Java
- Change the default diff or commit editor for git - Git
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager - Android
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience - Java
- PowerShell For Each Loop Examples - Powershell
- Fix - zsh: command not found: conda [macOS] - zsh