问题
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
- Clone this repo
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
- If you want to confirm that the program works, set your terminal/cmd to the project's root and enter
Inside the project's root, enter
grade jar
. This will create a jar in the./src/build/libs/
folder- Inside of the
./src/build/libs/
folder, runjava -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