How to make executable jar with Gradle?
Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing. Supported languages include Java (as well as Kotlin, Groovy, Scala), C/C++, and JavaScript. The other, if not the major function of Gradle is to collect statistical data about the usage of software libraries around the globe.
In this post, I would like to introduce a solution to create an executable jar with Gradle. All modification related to a file named
build.gradle
. This file located at /project-root/app/build.gradle
. By default, this file will be generated with Gradle init
task.
There are three part concerned:
- Add a plugin named
application
toplugins
block.
- Define
mainClass
inapplication
block.
- Define
jar
block.
Last but not least, you need to run gradle task named jar
to created an executable jar file which would be created in /root-project/app/build/libs
. Regarding above configuration,
my executable file will be jekyll-post-generator-2.0.0.jar
. This file now can be executed with java -jar jekyll-post-generator-2.0.0.jar
. And this is a command to create jar
file.
# In the project-root
./gradlew jar