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.
|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.
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.
Check in JVM options
The last step occurs when JVM options are tweaked using the
MVN_OPTS environment variable. It can be used to initialize the maximum amount of memory for the build e.g.
-XmX or to pass system properties to the build e.g.
-Dmy.property=3. Instead of using the
MVN_OPTS environment variable, such parameters should be set in a
.mvn/jvm.config file, and checked in along the app sources. Note this is available since Maven 3.3.1.
Check in JVM build options via the
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.
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 (
target configuration parameters of the
maven-compiler-plugin), one thing that cannot be set is the JDK itself.
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.