Nebula Project is a series of individual Gradle plugins, each focused on providing a very specific functionality in an usual Development Pipeline tasks. Today I'm gonna talk about one of those, nebula-os-package.
The main idea
The main idea behind It is to pack a JVM based application and Its metadata as a native OS package. The plugin is able to generate Deb and RPM packages, which are the most popular package formats on the Linux world.Using
First of all, add the plugin on your build.gradle file.
Then, add the specify the plugin dependency
Now you need to say how the application is gonna be set on Host, after the package is installed.
Couple of important things that are happening here:
Then, add the specify the plugin dependency
Now you need to say how the application is gonna be set on Host, after the package is installed.
Couple of important things that are happening here:
- Specifying package name and version (lines 2 and 3)
- Under which directory the package is gonna be placed after installed on the target Host (line 5).
- All jars produced by Gradle during the build (the application jar and Its dependencies), are gonna be placed under /opt/packageName/lib on the target Host. (line 8)
- Same thing for configuration files under the resource folder (line 18).
- The scripts generated by Gradle when building a Java application are gonna be used to start It up on the target Host (line 11).
With everything property set, just execute the build command accomplished by the package task specified on the build file. The Debian package is gonna be placed at projectName/build/distributions
So What?
Someone could be arguing:
- Why should I use this?
- Is It better than build a Fat jar with all Its dependencies inside!
- Gradle application plugin takes care of the whole Application start up for me generating useful scripts.
Yes, these are all valid points. Actually, this is the way we've being done so far when releasing applications outside of the J2EE world. But doing like this tasks like: deploy, start/stop, update and removing applications are all on you. Scripts will need to be create to manage all these, so one more thing that Ops and Dev teams will need to care about.
When deploying applications as Native OS packages, you can leverage a whole set of tools that are already there and none of the scripts mentioned before would be needed. This is a valid point when that affects agility when releasing and maintaining software.
Here I have a working example in case you wanna try It out.
Cheers,