Gradle Output Jar has no Main-Class

前端 未结 1 1991
时光取名叫无心
时光取名叫无心 2021-02-14 14:31

I have the following simple build.gradle file:

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

mainClassName = \'com.kurtis.HelloGradle\'

1条回答
  •  长情又很酷
    2021-02-14 15:17

    It's due to the way application plugin works. mainClassName is a property used by application plugin, when it creates an executable jar, it doesn't need to have a Main-Class in the manifest, since it doesn't use it.

    If you need to have a Main-Class in your jar, then you have to provide it vie jar configuration of the java plugin as follows:

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

    Otherwise, just use an executable, which is generated by application plugin, whether via run task or via distributions it can create for you, with scripts to run your application and all it's dependencies.

    0 讨论(0)
提交回复
热议问题