Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: Task 'run' not found in root project

Tags:

gradle

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?

like image 620
CrazySynthax Avatar asked Dec 17 '16 01:12

CrazySynthax


People also ask

How do I enable task in Gradle?

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.

What are tasks in Gradle?

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.


2 Answers

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'
like image 140
Paula T Avatar answered Sep 24 '22 13:09

Paula T


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.

like image 37
Vampire Avatar answered Sep 23 '22 13:09

Vampire