Gradle Jar It hasn't found the main class

Hi guys.

I’m getting a little trouble when I want to run my application, once I have created my Jar, The error that I’m getting is like I have written above in the topic.

Here, I show you my root project:

±-- Project ‘:lab-myapp-api’
±-- Project ‘:lab-myapp-commons’
±-- Project ‘:lab-myapp-config’
±-- Project ‘:lab-myapp-model’
±-- Project ‘:lab-myapp-service’
— Project ‘:lab-myapp-starter’

Where sub project lab-myapp-starter is my spring boot context and this is I want to run. When I run the application from my IDE IntelliJ the applicatio. works and process all requests, but When I have created my jar and It tries to run the application with Jar I haven’t could.

This is my gradle build file of the project.

apply plugin: ‘java’

sourceCompatibility = 1.8

repositories {

dependencies {
    annotationProcessor 'org.projectlombok:lombok:1.18.10'
    compileOnly 'org.projectlombok:lombok:1.18.10'
    testCompile group: 'junit', name: 'junit', version: '4.12'

jar {
    manifest {
                'Main-Class': 'com.mycompany.lab.myapp.starter.MyApplication'

    doFirst {
        manifest {
            if (!configurations.runtime.isEmpty()) {
                        configurations.runtime.collect{it.toURI().toString()}.join(' '))


group ‘com.mycompany’
version ‘1.0-SNAPSHOT’

Any idea or solution about that?

Thanks a lot for you help.

Hi @ggeliso,

I am not sure what the concrete problem is, but here are some pointers that should help you:

  • Consider using the application instead of the plain java plugin. Then Gradle will do all the work of creating the manifest and packaging the application for you -
  • If you absolutely need to do something manually, you should use configurations.runtimeClasspath instead of configurations.runtime (runtime is deprecated and might not always be complete).

Jendrik thanks for you answer.

Before, I want to be completely clear in my question, for that I say you the next:

My main issue is that I haven’t could to run my application from command line after of I have created an executable JVM application, the error that I’m getting is “It hasn’t been found or loaded the main class”.

I don’t know that I have something wrong in my gradle configuration, is for this reason I showed you the gradle build, in order to, you can see any error and you can say me any solution or give me any guide about my issue.

In the other hand, If my problem could be solving with your suggest, Could you give me a little more information or show me an example about how I can to implement the plugin application?

again, Thanks a lot.

Did you read the documentation on the application plugin I linked?

You can do this for example:

in lab-myapp-starter/build.gradle

plugins {
    id "application"
application {
    mainClassName = "com.mycompany.lab.myapp.starter.MyApplication"

And then you can run your application with:

./gradlew :lab-myapp-starter:run

Or get a fully packaged app with:

./gradlew :lab-myapp-starter:distZip