如何使用具有实现依赖性的Gradle创建可执行的胖jar [英] How do I create an executable fat jar with Gradle with implementation dependencies

查看:163
本文介绍了如何使用具有实现依赖性的Gradle创建可执行的胖jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Gradle 4.6中有一个简单的项目,并希望制作一个可执行的jar。我试过 shadow gradle-fatjar-plugin gradle-one-jar spring-boot-gradle-plugin 插件,但它们都没有添加我声明为实现的依赖项(我没有任何编译的)。它适用于编译,例如对于 gradle-one-jar 插件,但我希望实现依赖项。

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-jar, spring-boot-gradle-plugin plugins but neither of them adds my dependencies declared as implementation (I don't have any compile ones). It works with compile e.g. for gradle-one-jar plugin but I would like to have implementation dependencies.

非常感谢!

推荐答案

您可以使用以下代码。

jar {
    manifest {
        attributes(
                'Main-Class': 'your.main.class'
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
 }

这将打包运行时依赖。
如果您需要更多信息,请查看文档

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

这篇关于如何使用具有实现依赖性的Gradle创建可执行的胖jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆