In my previous post, I successfully managed to put all the output of Maven (and Eclipse) into RAM to reduce the disk write. In today post, I will do the same thing but with Gradle. Here is my build.gradle
apply plugin: "java"
apply plugin: "war"
apply plugin: "eclipse"
sourceCompatibility = 1.6
targetCompatibility = 1.6
group = "me.tinhtruong"
version = "1.0"
repositories {
mavenCentral()
}
dependencies {
compile "com.icegreen:greenmail:1.3.1b"
compile "jstl:jstl:1.2"
providedCompile "javax.servlet:servlet-api:2.5"
}
// Change the buildDir of the current project to /tmp/ (which is mounted on RAM using tmpfs)
buildDir = new File("/tmp/gradle/" + project.name);
// First, create a linked resource pointing to our Gradle buildDir, then hook into the .classpath file generation of Gradle to change the output of Eclipse to that linked resource.
eclipse {
project {
linkedResource name: 'build', type:'2', location: buildDir.absolutePath
}
classpath {
file {
whenMerged { classpath ->
classpath.entries.each { entry ->
if (entry.kind == 'output') {
entry.path = 'build/eclipse-output';
}
}
}
}
}
}
I've recently bought an Intel 520 SSD, so my top priority for my laptop is to reduce the disk write during daily use. In the Java world, Maven is one of the most common build tool out there. My most used Maven command is:
mvn clean package
This command will do a fresh build of the project, then copy all the compiled classes/resources to the build directory of Maven (which is the folder 'target', next to your source directory). If you have a large Maven project at hand, this command will perform thousands disk write (clean compiled classes and resources, then compile Java classes and assemble the resources into WAR/JAR file). By changing the build directory of Maven to /tmp (which is a tmpfs mountpoint (residing on RAM on my ArchLinux)), I can now rebuild my project as many times as I like without the write amplication concern. Here is now I do it in Maven:
- Define a property name target.directory with the default value is target
- Under the build section in your POM file, add this tag <directory>${target.directory}</directory>
- Modify your settings.xml file to include this snippet in your active profile:
/tmp/maven/${project.groupId}-${project.artifactId}/target
And the sample settings.xml file:4.0.0 com.abc abc war 1.0 Sampe Webapp http://www.abc.com target junit junit 3.8.1 test abc ${target.directory} maven-eclipse-plugin 2.8 true true target target 2 ${project.build.outputDirectory}
Happy coding!development /tmp/maven/${project.groupId}-${project.artifactId}/target public-snapshots development