Gradle Jar output has no main class

I have the following simple build.gradle file:

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

mainClassName = 'com.kurtis.HelloGradle'

And the following single Java file located at src/main/java/com/kurtis/HelloGradle.java:

package com.kurtis;

public class HelloGradle {

    public static void main(String[] args) {

        System.out.println("Hello gradle");
    }

}

However, if I run gradle build, I get jar in a directory build/libthat does not have a core set of classes. The manifest file has no entry Main-Class. Why is this?

+4
source share
1 answer

This is due to how the application plugin works. mainClassNameis a property used by the plugin applicationwhen it creates an executable jar, it does not need to be Main-Classin the manifest since it does not use it.

Main-Class , jar java java :

jar {
  manifest {
    attributes(
      'Main-Class': 'com.kurtis.HelloGradle'
    )
  }
}

, , run , , .

+8

Source: https://habr.com/ru/post/1673451/


All Articles