// By Brocken Inaglory (Own work) [CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons
:experimental: :icons: font
It sometimes happen that after a few years, an app is stable enough that it gets into hibernating mode. Though it’s used and useful, there are no changes to it and it happily runs its life. Then, after a while, someone decides to add some new features again. Apart from simple things such as locating the sources, one of the most important thing is to be able to build the app. Though it may seem trivial, there are some things to think about. Here are some advices on how to make apps that can be built forever.
TIP: I’ll use Maven as an example but advices below can apply to any build tool.
Immutable plugins version
For dependencies, Maven requires the version to be set. For plugins, Maven allows not to specify it. In that case, it will fetch the latest.
Though it might be seen as a benefit to always use the latest version, it can break existing behavior.
[IMPORTANT] .Rule 1 ==== Always explicitly set plugins version. This includes all plugins that are used during the build, even if they are not configured e.g.
Check in the build tool
The second problem that may arise is the build tool itself. What Maven version that was used to build the app? Building the app with another version might not work. Or worse, build the app in a slightly different way with unexpected side-effects.
Hence, the build tool must be saved along the sources of the app. In the Maven ecosystem, this can be done using the Maven wrapper.
[IMPORTANT] .Rule 2 ==== . Get the wrapper . Check it in along with regular sources . Use it for each and every build ====
Check in JVM options
The last step occurs when JVM options are tweaked using the
MVN_OPTSenvironment variable. It can be used to initialize the maximum amount of memory for the build e.g.
-XmXor to pass system properties to the build e.g.
-Dmy.property=3. Instead of using the
MVN_OPTSenvironment variable, such parameters should be set in a
.mvn/jvm.configfile, and checked in along the app sources. Note this is available since https://maven.apache.org/docs/3.3.1/release-notes.html#JVM_and_Command_Line_Options[Maven 3.3.1^].
[IMPORTANT] .Rule 3 ==== Check in JVM build options via the
.mvn/jvm.configfile along regular sources ====
Check in the CI build file
The build file that is relevant to the continuous integration server should be checked in as well. For some - Travis CI, GitLab, etc., it’s a pretty standard practice. For others - Jenkins, it’s a brand new feature.
[IMPORTANT] .Rule 4 ==== Check in the CI server specific build files along regular sources. ====
Nice to have
The above steps try to ensure that as many things as possible are immutable. While the version of the Java code and the version of the generated bytecode can be set (
targetconfiguration parameters of the
maven-compiler-plugin), one thing that cannot be set is the JDK itself.
In order to keep it immutable along the whole application life, it’s advised to specify the exact JDK. In turn, this depends a lot on the exact continuous integration server. For example, Travis CI allows it natively in the https://docs.travis-ci.com/user/languages/java/#Testing-Against-Multiple-JDKs[build file^], while Jenkins might require the usage of a https://jenkins.io/doc/book/pipeline/docker/[Docker image^].
Making sure to be able to build your app in the future is not a glamorous task. However, it can make a huge difference in the future. Following the above rules, chances you’ll be able to build apps, after they have been hibernating for a long time, will dramatically increase.
Posts Tagged ‘maintenance’