Over 10 years of developing web applications using Java technologies, I managed to see a huge number of fellow programmers and get acquainted with their methods of workflow organization. And, to my surprise, an absolute minority ever thought about using a RAM disk to build projects. I think that such an elementary optimization simply does not occur to me that is constantly busy with current tasks, deadlines and just life problems.
Meanwhile, the assembly in memory has two very significant advantages:
- Significant increase in assembly speed due to the lack of I / O operations on the hard disk (to a greater extent this applies to classic hard disks, especially with a rotation speed of 5400 revolutions per minute)
- Increase the lifetime of your SSD by moving intensive memory write operations
If we consider that in recent years, the amount of RAM on the computer of the average developer has greatly increased and SSDs are beginning to be used everywhere, then there are practically no arguments against.
The main goal of this short article is to cause a thought: “But really! And how did I not think about it before? ”.
')
I will describe an example of the implementation of this approach in Linux. Actions on other operating systems will be almost identical, except for the methods for creating the RAM disk itself.
Creating a ramdisk
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 a RAM disk and collect all the projects in it, this gives an additional advantage - the temporary files of other programs also do not use an SSD disk. An additional joyful fact is that all trash is removed 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 target it to the default assembly folder. This is done so that the changes you need do not affect other developers.
<project> ... <properties> <target.directory>${basedir}/target</target.directory> </properties> ... <build> <directory>${target.directory}</directory> ... </build> ... </project>
You should also pay attention to other places in the project's pom-files, which can use $ {basedir} / target.
For example on
jetty-maven-plugin <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.0.6.v20130930</version> <configuration> <war>${target.directory}/myproject-web</war> <classesDirectory>${target.directory}/classes</classesDirectory> <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory> <webApp> <contextPath>/</contextPath> <jettyEnvXml>${basedir}/src/main/resources/jetty-env.xml</jettyEnvXml> <defaultsDescriptor>${basedir}/src/main/resources/webdefault.xml</defaultsDescriptor> <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> </webApp> ... </configuration> ... </plugin>
The last step is to change the local Maven settings so that the variable $ {target.directory} has the value you need, 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 current user's “.m2” folder
gedit ~/.m2/settings.xml
Create a new profile
<profiles> ... <profile> <id>RAMBuild</id> <properties> <target.directory>/tmp/maven/${project.groupId}.${project.artifactId}/target</target.directory> </properties> </profile> ... </profiles>
Add a new profile to the list of active:
<activeProfiles> .... <activeProfile>RAMBuild</activeProfile> .... </activeProfiles>
That's all. I hope that now your builds will be faster and your drives will last longer.