How do I create an executable fat jar with Gradle with implementation dependencies

前端 未结 5 589
广开言路
广开言路 2020-12-01 09:02

I\'ve got a simple project in Gradle 4.6 and would like to make an executable jar of it. I\'ve tried shadow, gradle-fatjar-plugin, gradle-one

5条回答
  •  死守一世寂寞
    2020-12-01 09:33

    You can use the following code.

    jar {
        manifest {
            attributes(
                    'Main-Class': 'com.package.YourClass'
            )
        }
        from {
            configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
        }
     }
    

    Be sure to replace com.package.YourClass with the fully qualified class name containing static void main( String args[] ).

    This will pack the runtime dependencies. Check the docs if you need more info.

提交回复
热议问题