Mateusz Stefaniak Mateusz Stefaniak - 1 year ago 462
Java Question

Gradle error with lack of mainClassName property in gradle build

I have graddle configuration with two subprojects and when I want do build the project the following error is thrown:

Executing external task 'build'...
:core:processResources UP-TO-DATE
:core:startScripts FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':core:startScripts'.
> No value has been specified for property 'mainClassName'.

My configuration:
ROOT - build.gradle:

subprojects {

apply plugin: 'java'
apply plugin: 'application'

group = ''

repositories {

run {
main = project.getProperty('mainClassName')

jar {
manifest {
attributes 'Implementation-Title': project.getProperty('name'),
'Implementation-Version': project.getProperty('version'),
'Main-Class': project.getProperty('mainClassName')


task copyJars(type: Copy, dependsOn: subprojects.jar) {
into project.file('/jars')

ROOT - setting.gradle:

include 'app'
include 'core'

APP PROJECT - build.gradle:


CORE PROJECT - build.gradle:

dependencies {
compile ''
compile ''


version = 0.1-SNAPSHOT
name = MorePianer Core Lib
mainClassName =

I've tried to add the mainClassName property in many places, but it does not work. This is even stranger, that It worked a couple days ago as it is. I'm using gradle for first time and I'm thinking about switching back to maven.

Answer Source

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 file you might have to write it as : projectName.mainClassName = ..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download