Gradle - Could not find or load main class

Solution 1:

I see two problems here, one with sourceSet another with mainClassName.

  1. Either move java source files to src/main/java instead of just src. Or set sourceSet properly by adding the following to build.gradle.

    sourceSets.main.java.srcDirs = ['src']
    
  2. mainClassName should be fully qualified class name, not path.

    mainClassName = "hello.HelloWorld"
    

Solution 2:

Modify build.gradle to put your main class in the manifest:

jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version,
                   'Main-Class': 'hello.helloWorld'
    }
}