I'm trying to use the task 'run' in gradle and it seems that it doesn't exist in my project.
When I type in terminal:
$ gradle run
I get the error message:
FAILURE: Build failed with an exception.
What went wrong: Task 'run' not found in root project 'NA'.
I also built the project again, got "BUILD SUCCESSFUL", and it still didn't help me to commit the 'run' task.
How can I make 'run' task be useful again?
Configure running triggers for Gradle tasksIn the Gradle tool window, right-click a Gradle project. From the context menu, select Tasks Activation. On the Choose activation phase menu, choose when to run your task, for example, Before Build, After Sync, and so on.
In Gradle, Task is a single unit of work that a build performs. These tasks can be compiling classes, creating a JAR, Generating Javadoc, and publishing some archives to a repository and more. It can be considered as a single atomic piece of work for a build process.
You shouldn't need to manually create a task for run. If it's missing, it means there is something wrong with your build.gradle
In my case, my plugins was missing id 'application' and I didn't have a mainClassName declared at the end of the file. This is what my build.gradle looked like after run became an available task again:
plugins {
id 'java-library'
id 'application'
}
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:27.0.1-jre'
testImplementation 'junit:junit:4.12'
}
mainClassName = 'demo.App'
If you don't define a task called run
, there is no task called run
, so you cannot call a task called run
. Either define a task called run
that does what you want, or use some plugin that adds a task called run
that does what you want. For example the application
plugin adds a task called run
.
As you said "useful again" you can also track back what you changed from where it was working to where it it not working anymore and then undo it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With