`gradle jar`似乎没有在jar文件中添加依赖项 [英] `gradle jar` doesn't seem to be adding dependencies to jar file

查看:116
本文介绍了`gradle jar`似乎没有在jar文件中添加依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个可执行文件,该文件将自动创建带有相关任务的Google任务列表.

I'm wanting to make an executable file that will automatically create a Google Task list with associated tasks.

但是,现在,我正尝试使用Google提供的默认代码简单地创建可执行文件.

Right now, however, I'm trying to simply create an executable using the default code that Google provides here. Once you add the credentials.json file (explained below) and enter gradle run (in the repo I've provided) in a terminal/cmd, it will work as expectedly.

但是,如果您运行gradle jar创建一个jar,尝试运行jar时会出现此错误:

However, if you run gradle jar to create a jar, you will get this error when you try to run the jar:

java.lang.NoClassDefFoundError:com/google/api/client/json/JsonFactory

java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory


如何繁殖

  1. 克隆此存储库
  2. 通过单击

  3. 如果要确认程序可以正常运行,请将终端/cmd设置为项目的根目录,然后输入gradle run
  4. 在项目的根目录下,输入grade jar.这将在./src/build/libs/文件夹

    Inside the project's root, enter grade jar. This will create a jar in the ./src/build/libs/ folder

    这时,您将得到上面提到的错误.

    At this point, you will get the error mentioned above.

    推荐答案

    似乎您想要的是所谓的超级" jar(也包含其依赖项的jar)

    It seems that you want what's known as an "uber" jar (a jar that also contains its dependencies)

    您可以通过以下方式实现

    You can do this by

    jar {
       from configurations.runtime.collect { zipTree(it) } 
    } 
    

    这篇关于`gradle jar`似乎没有在jar文件中添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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