`gradle jar` doesn't seem to be adding dependencies to jar file

别等时光非礼了梦想. 提交于 2019-12-11 06:47:43

问题


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

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.

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


How to reproduce

  1. Clone this repo
  2. Download and replace the credentials.json file located in ./src/main/resources/ by clicking the "ENABLE THE GOOGLE TASKS API" on this page.

    • If you want to confirm that the program works, set your terminal/cmd to the project's root and enter gradle run
  3. Inside the project's root, enter grade jar. This will create a jar in the ./src/build/libs/ folder

  4. Inside of the ./src/build/libs/ folder, run java -jar demo-1.0.jar

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


回答1:


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) } 
} 


来源:https://stackoverflow.com/questions/56865762/gradle-jar-doesnt-seem-to-be-adding-dependencies-to-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!