Merge pull request #188 from d4mian/minor-changes
[voldemort/jeffpc.git] / build.gradle
blob0d8d09ed4042604643d93c4eabdf2f30838c9373
1 import java.util.jar.JarEntry;
3 apply plugin: 'java'
4 apply plugin: 'scala'
5 apply plugin: 'idea'
7 def String getProjectProperty(String propertyName) {
8     String propertyValue = "null"
9     if (hasProperty(propertyName)) {
10         propertyValue = this.properties[propertyName]
11     }
12     else {
13         throw GradleScriptException("PropertyName " + propertyName + " is not defined in properties file")
14     }
15     return propertyValue
17 def projectName = "voldemort"
19 def sourceDir = getProjectProperty('src.dir')
20 def distDir = getProjectProperty('dist.dir')
21 def classesDir = getProjectProperty('classes.dir')
22 def javaDir = getProjectProperty('java.dir')
23 def libDir = getProjectProperty('lib.dir')
24 def resourcesDir = getProjectProperty('resources.dir')
25 def javaDocDir = getProjectProperty('javadoc.dir')
27 def voldTestClassesDir = getProjectProperty('testclasses.dir')
29 def commonTestSrcDir = getProjectProperty('commontestsrc.dir')
30 def unitTestSrcDir = getProjectProperty('unittestsrc.dir')
31 def intTestSrcDir = getProjectProperty('inttestsrc.dir')
32 def longTestSrcDir = getProjectProperty('longtestsrc.dir')
34 def contribClassesDir = getProjectProperty('contrib.classes.dir')
35 def contribRootDir = getProjectProperty('contrib.root.dir')
37 def voldVersion = getProjectProperty('curr.release')
38 def javacVersion = getProjectProperty('javac.version')
39 def scalaVersion = getProjectProperty('scalac.version')
41 //This is the javaCompile variable version. Directly defining 'def version' will override this and cause nightmare
42 version = voldVersion
44 def archiveDirectoryName = projectName + '-' + version
45 def archiveDirectoryPath = distDir + "/" + archiveDirectoryName
47 def deleteDirectoryContents(directory) {
48     project.file(directory).deleteDir()
49     project.file(directory).mkdirs()
52 println 'java source target compatibility version ' + javacVersion
53 sourceCompatibility = javacVersion
54 targetCompatibility = javacVersion
55 compileJava.options.debug = true
58 tasks.withType(ScalaCompile) {
59     scalaClasspath = files("lib/scala-compiler-${scalaVersion}.jar",
60             "lib/scala-reflect-${scalaVersion}.jar",
61             "lib/scala-library-${scalaVersion}.jar")
64 repositories {
65     flatDir { dirs libDir }
66     flatDir { dirs contribRootDir }
70 sourceSets {
71     main {
72         java { srcDirs = [javaDir]}
73         scala {
74             srcDirs = [sourceDir]
75             include '**/*.scala'
76         }
77         resources {
78             srcDirs = [javaDir]
79             include '**/*.xsd'
80         }
81         output.classesDir = classesDir
82         output.resourcesDir = resourcesDir
83     }
84     test {
85         java {
86             srcDirs = [
87                 commonTestSrcDir ,
88                 unitTestSrcDir,
89                 intTestSrcDir ,
90                 longTestSrcDir
91             ]
92         }
93         output.classesDir = voldTestClassesDir
94     }
95     contrib {
96         java { srcDirs = [contribRootDir] }
97         compileClasspath += sourceSets.main.runtimeClasspath
98         output.classesDir = contribClassesDir
99     }
102 compileJava.doLast {
103     project.copy {
104         from (javaDir) { exclude '**/*.java','**/*.html','**/*.scala', '**/log4j.properties' }
105         into classesDir
106     }
108     project.copy {
109         // Theoretically this block can be replaced by including the log4j.properties in main resources.
110         // But that causes the log4j.properties to be present in the voldJar . Not sure what is the
111         // implication of this change, so avoiding it for now.
112         from (javaDir) { include 'log4j.properties' }
113         into resourcesDir
114     }
117 compileTestJava.doLast {
118     project.copy {
119         from (commonTestSrcDir) { exclude '**/*.java','**/*.html' }
120         from (unitTestSrcDir) { exclude '**/*.java','**/*.html' }
121         into voldTestClassesDir
122     }
125 compileContribJava.doLast {
126     project.copy {
127         from (contribRootDir + '/ec2-testing/resources')
128         into contribClassesDir
129     }
132 dependencies {
133     compile fileTree(dir: libDir, includes: ['**/*.jar'])
135     contribCompile sourceSets.main.output
136     contribCompile sourceSets.test.output
138     contribCompile fileTree(dir: contribRootDir, includes: ['**/*.jar'])
139     testCompile 'junit:junit:4.6'
142 task testJar(type: Jar) {
143     baseName = projectName + "-test"
144     from sourceSets.test.output
145     destinationDir = project.file(distDir)
148 task voldJar(type:Jar) {
149     baseName = projectName
150     manifest {
151         attributes 'Voldemort-Implementation-Version' : version,
152         'Implementation-Title': 'Voldemort',
153         'Implementation-Version': version,
154         'Implementation-Vendor' :'LinkedIn'
155     }
156     from sourceSets.main.output
157     destinationDir = project.file(distDir)
160 task contribJar(type:Jar) {
161     dependsOn voldJar, testJar, sourceSets.contrib.output
162     baseName = projectName + "-contrib"
163     from sourceSets.contrib.output
164     destinationDir = project.file(distDir)
167 task srcJar(type: Jar, dependsOn: classes) {
168     classifier = 'src'
169     from sourceSets.main.java.srcDirs
170     destinationDir = project.file(distDir)
173 artifacts {
174     archives voldJar
175     archives testJar
176     archives contribJar
177     archives srcJar
180 clean {
181     delete(distDir)
182     doLast { deleteDirectoryContents(javaDocDir) }
185 task copySources (type: Copy) {
186     from ('.') { include 'bin/**' }
187     from ('.') { include  distDir + '/*.jar'}
188     from ('.') { exclude distDir + '/**' ,'bin/**' , 'build/**', '.git/**' , '.gradle/**' }
189     into archiveDirectoryPath
192 task zip (type: Zip) {
193     dependsOn copySources
194     baseName = projectName
196     from(distDir) {
197         include archiveDirectoryName + '/bin/**'
198         fileMode = 0755
199     }
200     from(distDir) {
201         include archiveDirectoryName + '/**'
202         exclude archiveDirectoryName + '/bin/**'
203     }
205     destinationDir = project.file(distDir)
208 task tar (type: Tar) {
209     dependsOn copySources
210     compression = Compression.GZIP
211     baseName = projectName
212     extension = "tar.gz"
214     from(distDir) {
215         include archiveDirectoryName + '/bin/**'
216         fileMode = 0755
217     }
218     from(distDir) {
219         include archiveDirectoryName + '/**'
220         exclude archiveDirectoryName + '/bin/**'
221     }
223     destinationDir = project.file(distDir)
226 jar.dependsOn contribJar,srcJar
227 compileContribJava.dependsOn voldJar
228 copySources.dependsOn jar
230 tasks.withType(Test) {
231     // ant restarts jvm for each tests, If not restarted the test runs into outOfMemory even
232     // if you set the JVM to 8gb. On inspecting most of the space is consumed by int[] of
233     // Histogram in the NioSelectorManager. I believe this could be explained by
234     // creating lots of client factory which creates lot of NIO threads. Did not proceed
235     // further as I will be maintaining compatbility with ant. Also if you dont fork for each
236     // tests JMX bean related tests will fail.
238     // Do not set the max parallelism as there are tests that uses the same port and will
239     // run into bind exceptions.
240     maxHeapSize = "2g"
241     forkEvery = 1
244     // If ignoreFailures is not set, then merged reports will not be generated
245     // Gradle aborts further tasks on test failure. so if you run junitAll
246     // which runs 3 tests, reports task will never be run on failure cases.
247     ignoreFailures = true
249     useJUnit()
251     testLogging {
252         events "passed", "skipped", "failed"
253         exceptionFormat = 'full'
254     }
256     afterTest { test, result ->
257         logger.lifecycle("testFinished: $test, result: $result.resultType")
258     }
260     doFirst {
261       def classesSize = candidateClassFiles.files.size()
262       logger.lifecycle("{} starts executing {} test classes {}",
263           path, classesSize, classesSize > 0? "(" + candidateClassFiles.files*.name[0] + ", ...)" : "")
264     }
266     //all standard error messages from tests will get routed to 'DEBUG' level messages.
267     //logging.captureStandardError(LogLevel.DEBUG)
268     //all standard output messages from tests will get routed to 'DEBUG' level messages.
269     //logging.captureStandardOutput(LogLevel.DEBUG)
271     //Set reasonable defaults for reports location
272     reports.html.destination = file("$project.buildDir/reports/$name")
273     reports.junitXml.destination = file("$project.buildDir/$name-results")
275     //Set reasonable defaults classpath and classes dir. They can be reconfigured in an individual task.
276     it.testClassesDir = sourceSets.test.output.classesDir
277     classpath = sourceSets.test.runtimeClasspath
280 task junit(dependsOn: test)
282 Collection<String> testClassesFrom(String dir, String include = '**/*Test.*') {
283   //take all *Test.java files found in given dir, make the path relative and replace .java with .class
284   fileTree(dir: dir, includes: [include]).collect { it.absolutePath.replaceAll(file(dir).absolutePath + "/", "").replaceAll(".java\$", ".class")}
287 test {
288     description = "Runs acceptance tests"
289     include testClassesFrom(unitTestSrcDir)
292 task junitLong(type: Test) {
293     description = "Runs long junit tests"
294     include testClassesFrom(longTestSrcDir)
297 task junitRebalance(type: Test) {
298   include testClassesFrom(unitTestSrcDir, '**/*Rebalance*Test.java')
301 task junitRebalanceLong(type: Test) {
302   include testClassesFrom(longTestSrcDir, '**/*Rebalance*Test.java')
305 task contribJunit(type: Test) {
306     description = "Run contrib junit tests except EC2 and Krati tests."
307     it.testClassesDir = file(contribClassesDir)
309     exclude '**/*PerformanceTest.class'
310     exclude '**/*RemoteTest.class'
311     exclude '**/Ec2*Test.class'
312     exclude '**/Krati*Test.class'
313     exclude '**/HadoopStoreBuilder*Test.class'
315     classpath += sourceSets.contrib.runtimeClasspath + sourceSets.contrib.output
318 task junitAll(type: TestReport) {
319     reportOn test, junitLong, contribJunit
320     destinationDir = file("$project.buildDir/reports/$name")
323 task aggregatedJunit(type: TestReport) {
324 destinationDir = file("$project.buildDir/reports/$name")
327 tasks.withType(Test) {
328   finalizedBy aggregatedJunit
329   doLast {
330     aggregatedJunit.reportOn it.binResultsDir
331   }
334 task wrapper(type: Wrapper) {
335     gradleVersion = '1.12'