Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle error with lack of mainClassName property in gradle build

Tags:

java

gradle

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:compileJava :core:processResources UP-TO-DATE :core:classes :core:jar :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 = 'pl.morecraft.dev.morepianer'      repositories {         mavenLocal()         mavenCentral()     }      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) {     from(subprojects.jar)     into project.file('/jars') } 

ROOT - setting.gradle:

include 'app' include 'core' 

APP PROJECT - build.gradle:

EMPTY

CORE PROJECT - build.gradle:

dependencies {     compile 'com.google.dagger:dagger:2.4'     compile 'com.google.dagger:dagger-compiler:2.4' } 

AND BOTH SUBPROJECTS (SIMILAR) - gradle.properties:

version = 0.1-SNAPSHOT name = MorePianer Core Lib mainClassName = pl.morecraft.dev.morepianer.core.Core 

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.

like image 530
Mateusz Stefaniak Avatar asked Apr 28 '16 14:04

Mateusz Stefaniak


2 Answers

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 = ..

like image 162
zlandorf Avatar answered Sep 22 '22 21:09

zlandorf


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

like image 33
Mika16 Avatar answered Sep 22 '22 21:09

Mika16