We collect the project on a RAM disk using Maven
Meanwhile, the memory assembly has two very significant advantages:
- A significant increase in assembly speed due to the lack of input / output operations on the hard drive (this is more true for classic hard drives, especially with a rotation speed of 5400 rpm)
- Increase the lifetime of your SSD by moving intensive write operations to memory
Considering that in recent years the amount of RAM on the computer of an average developer has grown significantly and SSDs are beginning to be used everywhere, there are practically no arguments against.
The main goal of this short article is to provoke the thought: “But really! And how had I not thought about this before? ”
I will describe an example implementation of this approach in Linux. Actions on other operating systems will be almost identical, with the exception of the methods for creating the RAM disk itself.
RAM disk creation
Edit the / etc / fstab file with your favorite editor, for example:
gksudo -k gedit /etc/fstab
Add to it the term
tmpfs /tmp tmpfs mode=1777 0 0
I prefer to mount the / tmp folder on the RAM disk and collect all the projects in it, this gives an additional advantage - temporary files of other programs also do not use the SSD disk. An additional joyful fact is that all garbage is deleted automatically when the computer is restarted.
Maven setup
First you need to enter an additional parameter in the root pom-file of the project, which will point to the assembly folder and aim it at the default assembly folder. This is done so that the changes you need do not affect other developers.
...
${basedir}/target
...
${target.directory}
...
...
You should also pay attention to other places in the project pom-files that can use $ {basedir} / target.
For example on
org.eclipse.jetty jetty-maven-plugin 9.0.6.v20130930 ${target.directory}/myproject-web ${target.directory}/classes ${basedir}/src/main/webapp / ${basedir}/src/main/resources/jetty-env.xml ${basedir}/src/main/resources/webdefault.xml ${basedir}/src/main/webapp/WEB-INF/web.xml
...
...
The last step remains - changing the local Maven settings so that the variable $ {target.directory} has the value you need, and not the value specified in the pom file.
Copy the Maven configuration file to ~ / .m2 (if necessary)
cp /usr/share/maven/conf/settings.xml ~/.m2/settings.xml
Edit settings.xml in the ".m2" folder of the current user
gedit ~/.m2/settings.xml
Create a new profile
...
RAMBuild /tmp/maven/${project.groupId}.${project.artifactId}/target
...
Add a new profile to the list of active:
....
RAMBuild
....
That's all. I hope that now your builds will be faster and the disks will be more durable.