Reputation: 157
My "build.gradle" file:
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
My "Main.java" file in "./src/" directory:
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
System.out.println("Hello Gradle");
}
}
I get this error:
Task 'run' not found in root project 'gradleNew'
Sorry for the stupid question... I didn't use Gradle before
Upvotes: 1
Views: 16595
Reputation: 58
The java
plugin does not include the run
task, which I suppose your gradle build requires somewhere in your app.
Change the java
plugin to application
and you should be fine.
To verify this, you can go to your project folder inside you terminal and run gradle tasks
. You should see the run
task listed among other tasks.
I hope that helps.
Upvotes: 2
Reputation: 2874
Try this instead:
group 'com.example'
version '1.0'
apply plugin: 'application' // implicitly includes the java plugin
sourceCompatibility = 1.11 // java version 11
repositories {
mavenCentral()
}
dependencies {
// your dependencies
}
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
}
I typically use something similar to this for my projects. You can then explicitly create the relevant dirs for src/test code, or sometimes the IDE will do it for you when you point it to the relevant build.gradle
file (you can typically restart the IDE and it will pick up the file, or you can open a new project and select the build.gradle
file as the project to open if it doesn't identify it right away).
Upvotes: 0
Reputation: 157
I just add this code and my app run:
plugins {
id 'application'
}
Upvotes: 1