Gradle error with lack of mainClassName property in gradle build

The application plugin needs to know the main class for when it bundles the application.

In your case, you apply the application plugin for each subproject without specifying the main class for each of those subprojects.

I had the same problem and fixed it by specifying "mainClassName" at the same level as apply plugin: 'application' :

apply plugin: 'application'
mainClassName = 'com.something.MyMainClass'

If you want to specify it in the gradle.properties file you might have to write it as : projectName.mainClassName = ..


Instead of setting up mainClassName try to create

task run(type: JavaExec, dependsOn: classes) {
    main = 'com.something.MyMainClass'
    classpath = sourceSets.main.runtimeClasspath
}

Please look at Gradle fails when executes run task for scala


Whenever we bind a gradle script with the application plugin, Gradle expects us to point out the starting point of the application. This is neccessary because, Gradle will start bundling your application (jar/zip) using the given location as the entry point.
This error is thrown simply because Gradle knows that you want to bundle your application but is clueless about where to start the bundling process.

Tags:

Java

Gradle