hudson run fails to copy mysql
[voldemort/jeffpc.git] / build.gradle
blob203990b3400738bb3ff9abe06997cd56d5d22906
1 import java.util.jar.JarEntry;
3 apply plugin: 'java'
4 apply plugin: 'scala'
5 apply plugin: 'idea'
6 apply plugin: 'eclipse'
7 apply plugin: 'war'
9 def String getProjectProperty(String propertyName) {
10     String propertyValue = "null"
11     if (hasProperty(propertyName)) {
12         propertyValue = this.properties[propertyName]
13     }
14     else {
15         throw GradleScriptException("PropertyName " + propertyName + " is not defined in properties file")
16     }
17     return propertyValue
19 def projectName = "voldemort"
21 def sourceDir = getProjectProperty('src.dir')
22 def distDir = getProjectProperty('dist.dir')
23 def classesDir = getProjectProperty('classes.dir')
24 def javaDir = getProjectProperty('java.dir')
25 def privateLibDir = getProjectProperty('private.lib.dir')
26 def resourcesDir = getProjectProperty('resources.dir')
27 def javaDocDir = getProjectProperty('javadoc.dir')
29 def voldTestClassesDir = getProjectProperty('testclasses.dir')
31 def commonTestSrcDir = getProjectProperty('commontestsrc.dir')
32 def unitTestSrcDir = getProjectProperty('unittestsrc.dir')
33 def intTestSrcDir = getProjectProperty('inttestsrc.dir')
34 def longTestSrcDir = getProjectProperty('longtestsrc.dir')
36 def contribClassesDir = getProjectProperty('contrib.classes.dir')
37 def contribRootDir = getProjectProperty('contrib.root.dir')
39 def voldVersion = getProjectProperty('curr.release')
40 def javacVersion = getProjectProperty('javac.version')
41 def scalaVersion = getProjectProperty('scalac.version')
43 //This is the javaCompile variable version. Directly defining 'def version' will override this and cause nightmare
44 version = voldVersion
46 def archiveDirectoryName = projectName + '-' + version
47 def archiveDirectoryPath = distDir + "/" + archiveDirectoryName
49 def deleteDirectoryContents(directory) {
50     project.file(directory).deleteDir()
51     project.file(directory).mkdirs()
54 println 'java source target compatibility version ' + javacVersion
55 sourceCompatibility = javacVersion
56 targetCompatibility = javacVersion
57 compileJava.options.debug = true
60 tasks.withType(ScalaCompile) { scalaCompileOptions.useAnt = false }
62 repositories {
63     mavenCentral()
64     flatDir { dirs privateLibDir }
65     flatDir { dirs contribRootDir }
69 sourceSets {
70     main {
71         java { srcDirs = [javaDir]}
72         scala {
73             srcDirs = [sourceDir]
74             include '**/*.scala'
75         }
76         resources {
77             srcDirs = [javaDir]
78             include '**/*.xsd'
79         }
80         output.classesDir = classesDir
81         output.resourcesDir = resourcesDir
82     }
83     test {
84         java {
85             srcDirs = [
86                 commonTestSrcDir ,
87                 unitTestSrcDir,
88                 intTestSrcDir ,
89                 longTestSrcDir
90             ]
91         }
92         output.classesDir = voldTestClassesDir
93     }
94     contrib {
95         java { srcDirs = [contribRootDir]}
96         compileClasspath += sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
97         output.classesDir = contribClassesDir
98     }
101 compileJava.doLast {
102     project.copy {
103         from (javaDir) { exclude '**/*.java','**/*.html','**/*.scala', '**/log4j.properties' }
104         into classesDir
105     }
107     project.copy {
108         // Theoretically this block can be replaced by including the log4j.properties in main resources.
109         // But that causes the log4j.properties to be present in the voldJar . Not sure what is the
110         // implication of this change, so avoiding it for now.
111         from (javaDir) { include 'log4j.properties' }
112         into resourcesDir
113     }
116 compileTestJava.doLast {
117     project.copy {
118         from (commonTestSrcDir) { exclude '**/*.java','**/*.html' }
119         from (unitTestSrcDir) { exclude '**/*.java','**/*.html' }
120         into voldTestClassesDir
121     }
124 compileContribJava.doLast {
125     project.copy {
126         from (contribRootDir + '/ec2-testing/resources')
127         into contribClassesDir
128     }
131 task testJar(type: Jar) {
132     baseName = projectName + "-test"
133     from sourceSets.test.output
134     destinationDir = project.file(distDir)
137 task voldJar(type:Jar) {
138     baseName = projectName
139     manifest {
140         attributes 'Voldemort-Implementation-Version' : version,
141         'Implementation-Title': 'Voldemort',
142         'Implementation-Version': version,
143         'Implementation-Vendor' :'LinkedIn'
144     }
145     from sourceSets.main.output
146     destinationDir = project.file(distDir)
149 war {
150     from sourceSets.main.output
151     webXml = project.file('web.xml')
152     destinationDir = project.file(distDir)
155 task contribJar(type:Jar) {
156     dependsOn voldJar, testJar, sourceSets.contrib.output
157     baseName = projectName + "-contrib"
158     from sourceSets.contrib.output
159     destinationDir = project.file(distDir)
162 task srcJar(type: Jar, dependsOn: classes) {
163     classifier = 'src'
164     from sourceSets.main.java.srcDirs
165     destinationDir = project.file(distDir)
168 artifacts {
169     archives voldJar
170     archives testJar
171     archives contribJar
172     archives srcJar
175 clean {
176     delete(distDir)
177     delete('lib')
178     doLast { deleteDirectoryContents(javaDocDir) }
181 task copySources (type: Copy) {
182     from ('.') { include 'bin/**' }
183     from ('.') { include  distDir + '/*.jar'}
184     from ('.') { exclude distDir + '/**' ,'bin/**' , 'build/**', '.git/**' , '.gradle/**' }
185     into archiveDirectoryPath
188 task zip (type: Zip) {
189     dependsOn copySources
190     baseName = projectName
192     from(distDir) {
193         include archiveDirectoryName + '/bin/**'
194         fileMode = 0755
195     }
196     from(distDir) {
197         include archiveDirectoryName + '/**'
198         exclude archiveDirectoryName + '/bin/**'
199     }
201     destinationDir = project.file(distDir)
204 task tar (type: Tar) {
205     dependsOn copySources
206     compression = Compression.GZIP
207     baseName = projectName
208     extension = "tar.gz"
210     from(distDir) {
211         include archiveDirectoryName + '/bin/**'
212         fileMode = 0755
213     }
214     from(distDir) {
215         include archiveDirectoryName + '/**'
216         exclude archiveDirectoryName + '/bin/**'
217     }
219     destinationDir = project.file(distDir)
222 task copyDeps(type: Copy) {
223     from  {configurations.compile  }
224     into "lib"
228 jar.dependsOn contribJar,srcJar, copyDeps
229 compileContribJava.dependsOn voldJar
230 copySources.dependsOn jar
232 tasks.withType(Test) {
233     // ant restarts jvm for each tests, If not restarted the test runs into outOfMemory even
234     // if you set the JVM to 8gb. On inspecting most of the space is consumed by int[] of
235     // Histogram in the NioSelectorManager. I believe this could be explained by
236     // creating lots of client factory which creates lot of NIO threads. Did not proceed
237     // further as I will be maintaining compatbility with ant. Also if you dont fork for each
238     // tests JMX bean related tests will fail.
240     // Do not set the max parallelism as there are tests that uses the same port and will
241     // run into bind exceptions.
242     maxHeapSize = "2g"
243     forkEvery = 1
246     // If ignoreFailures is not set, then merged reports will not be generated
247     // Gradle aborts further tasks on test failure. so if you run junitAll
248     // which runs 3 tests, reports task will never be run on failure cases.
249     ignoreFailures = true
250     //ignoreFailures = gradle.startParameter.continueOnFailure
252     useJUnit()
254     testLogging {
255         events "passed", "skipped", "failed"
256         exceptionFormat = 'full'
257     }
259     afterTest { test, result ->
260         logger.lifecycle("testFinished: $test, result: $result.resultType")
261     }
263     doFirst {
264         def classesSize = candidateClassFiles.files.size()
265         logger.lifecycle("{} starts executing {} test classes {}",
266                 path, classesSize, classesSize > 0? "(" + candidateClassFiles.files*.name[0] + ", ...)" : "")
267     }
269     //all standard error messages from tests will get routed to 'DEBUG' level messages.
270     //logging.captureStandardError(LogLevel.DEBUG)
271     //all standard output messages from tests will get routed to 'DEBUG' level messages.
272     //logging.captureStandardOutput(LogLevel.DEBUG)
274     //Set reasonable defaults for reports location
275     reports.html.destination = file("$project.buildDir/reports/$name")
276     reports.junitXml.destination = file("$project.buildDir/$name-results")
278     //Set reasonable defaults classpath and classes dir. They can be reconfigured in an individual task.
279     it.testClassesDir = sourceSets.test.output.classesDir
280     classpath = sourceSets.test.runtimeClasspath
283 task junit(dependsOn: test)
285 Collection<String> testClassesFrom(String dir, String include = '**/*Test.*') {
286     //take all *Test.java files found in given dir, make the path relative and replace .java with .class
287     fileTree(dir: dir, includes: [include]).collect { it.absolutePath.replaceAll(file(dir).absolutePath + "/", "").replaceAll(".java\$", ".class")}
290 test {
291     description = "Runs acceptance tests"
292     include testClassesFrom(unitTestSrcDir)
295 task junitLong(type: Test) {
296     description = "Runs long junit tests"
297     include testClassesFrom(longTestSrcDir)
300 task junitRebalance(type: Test) {
301     include testClassesFrom(unitTestSrcDir, '**/*Rebalance*Test.java')
304 task junitRebalanceLong(type: Test) {
305     include testClassesFrom(longTestSrcDir, '**/*Rebalance*Test.java')
308 task contribJunit(type: Test) {
309     description = "Run contrib junit tests except EC2 and Krati tests."
310     it.testClassesDir = file(contribClassesDir)
312     exclude '**/*PerformanceTest.class'
313     exclude '**/*RemoteTest.class'
314     exclude '**/Ec2*Test.class'
315     exclude '**/Krati*Test.class'
316     exclude '**/HadoopStoreBuilder*Test.class'
318     classpath += sourceSets.contrib.runtimeClasspath + sourceSets.contrib.output
321 task junitAll(type: TestReport) {
322     reportOn test, junitLong, contribJunit
323     destinationDir = file("$project.buildDir/reports/$name")
326 task aggregatedJunit(type: TestReport) {
327     destinationDir = file("$project.buildDir/reports/$name")
330 tasks.withType(Test) {
331     finalizedBy aggregatedJunit
332     doLast { aggregatedJunit.reportOn it.binResultsDir }
335 task wrapper(type: Wrapper) { gradleVersion = '1.12' }
338 dependencies {
339     // Avro serialization format
340     compile 'org.apache.avro:avro:1.4.0'
342     // INTERNAL_LIBS azkaban version not found
343     // azkaban-common-0.05.jar
345     // INTERNAL_LIBS Used for tomcat deployment, not sure if anyone uses it
346     // catalina-ant.jar , version not found in maven central
348     // coders decoders containing the Base64,binary encoding
349     compile 'commons-codec:commons-codec:1.4'
351     // TRANSITIVE_DEPENDENCY Contrib jar depends on commons-configuration-1.6.jar
352     // commons-configuration instead depends on commons-collection
353     //compile 'commons-collections:commons-collections:3.2.1'
355     // Used by MySql storage engine classes
356     // The jar supports database connection pooling
357     compile 'commons-dbcp:commons-dbcp:1.2.2'
359     // commons io is used at many places
360     // IOUtils, FileUtils and ByteArrayOutputStream
361     compile 'commons-io:commons-io:1.4'
363     // LZF compression strategy for store and tests.
364     compile 'com.ning:compress-lzf:0.9.1'
366     // TRANSITIVE_DEPENDENCY tusk jar internally uses gson.
367     compile 'com.google.code.gson:gson:2.2.4'
369     // Used all over the place for collections
370     compile 'com.google.guava:guava:14.0.1'
372     // used for readonly store hdfs fetcher.
373     compile 'org.apache.hadoop:hadoop-auth:2.0.5-alpha'
375     // used at lots of places. Seems like there is some overlap between httpclient and core, but not clear
376     compile 'org.apache.httpcomponents:httpclient:4.1.2'
378     // contains both http server and client functionalities. Used for HttpResponse but could be used at more places.
379     compile 'org.apache.httpcomponents:httpcore:4.1.2'
381     // JSON mapping library from Java Objects to JSON
382     compile 'org.codehaus.jackson:jackson-mapper-asl:1.4.0'
384     // JSON processing library
385     compile 'org.codehaus.jackson:jackson-core-asl:1.4.0'
387     // Used for reading XML files and Document.
388     compile 'jdom:jdom:1.1'
390     // je- BDB je 5.0.88 is not available in maven central repository.
391     // Could be possibly found in oracle maven repository, but not sure
392     /*
393      groupId>com.sleepycat</groupId>
394      <artifactId>je</artifactId>
395      <version>3.3.75</version>
396      groupId>com.sleepycat</groupId>
397      <artifactId>je</artifactId>
398      <version>3.3.75</version>
399      */
401     // Jetty is used for HttpService and tests. Jetty Util is used for QueuedThreadPool class.
402     compile 'org.mortbay.jetty:jetty-util:6.1.18'
403     compile 'org.mortbay.jetty:jetty:6.1.18'
405     // A line processing library for command line. No compile time dependency
406     // Used by Voldemort shell
407     compile 'jline:jline:0.9.94'
409     // jna is library for invoking native functions
410     // used in the readonly store
411     compile 'net.java.dev.jna:jna:3.2.7'
413     // joda time is replacement for Java Date and Time
414     // used in readonly store code.
415     compile 'joda-time:joda-time:1.6'
417     // Used for argument command line parsing
418     compile 'net.sf.jopt-simple:jopt-simple:4.6'
420     // INTERNAL_LIBS thrift is one of the supported serialization format.
421     // libthrift 0.5 version is not found in the maven central repository.
422     // The closest version available is 0.6.1
423     // libthrift-0.5.0.jar
425     // log4j - logger used in almost all files
426     compile 'log4j:log4j:1.2.15'
428     // used in readonly store and Co-ordinator
429     compile 'javax.mail:mail:1.4.1'
431     // Used in co-ordinator and rest services
432     compile 'io.netty:netty:3.5.8.Final'
434     // TRANSITIVE_DEPENDENCY Paranamer is a library that allows the parameter names of non-private methods and constructors to be accessed at runtime
435     // Avro has a dependency on paranamer
436     // compile 'com.thoughtworks.paranamer:paranamer:2.1'
438     // protobuf is a supported protocol format between voldemort client and server
439     compile 'com.google.protobuf:protobuf-java:2.3.0'
441     // Command line shell is also supported in scala
442     compile 'org.scala-lang:scala-compiler:2.10.4'
443     compile 'org.scala-lang:scala-library:2.10.4'
444     compile 'org.scala-lang:scala-reflect:2.10.4'
446     // Servlet
447     compile 'javax.servlet:servlet-api:2.5'
449     // slf4j is another logging abstraction framework.
450     // It is used by the apache.avro, apache.hadoop and r2 clients
451     compile 'org.slf4j:slf4j-api:1.5.6'
452     compile 'org.slf4j:slf4j-log4j12:1.5.6'
454     // snappy is one of the supported compression strategies in voldemort
455     compile 'org.iq80.snappy:snappy:0.2'
457     // could not locate tusk in maven central repository
458     // tusk-0.0.2.jar
460     // Velocity is a simple yet powerful Java-based template engine that renders data
461     // from plain Java objects to text, xml, email, SQL, Post Script, HTML etc
462     // Velocity is used for Http Server GUI
463     compile 'org.apache.velocity:velocity:1.6.2'
465     // TRANSITIVE_DEPENDENCY Apache XML Parser
466     // used by jdom
467     // compile 'xerces:xercesImpl:2.9.1'
469     compile fileTree(dir: privateLibDir, includes: ['**/*.jar'])
471     // cern library containing high performance Maps for int and double
472     // Currently only used in the tests
473     testCompile 'colt:colt:1.2.0'
475     // Used in ec2 testing , is a wrapper over any logging framework
476     testCompile 'commons-logging:commons-logging:1.1.1'
478     // Used in resource pool perf testing class
479     testCompile 'commons-pool:commons-pool:1.5.2'
481     testRuntime 'mysql:mysql-connector-java:5.1.31'
483     // Used for unit tests and other automated testing
484     testCompile 'junit:junit:4.6'
486     // Mockito is written by our beloved friend Szczepan Faber :)
487     // Mocking framework used in some tests
488     testCompile 'org.mockito:mockito-all:1.8.5'
490     contribCompile sourceSets.main.output
491     contribCompile sourceSets.test.output
493     // declaring contribCompile dependencies as compile dependencies
494     // otherwise while copying dependencies to lib directory
495     // conflict resolution is not done properly across sourceSets
496     // and we end up with 2 versions of few jars like ( log4j, servlet etc. )
497     compile 'commons-configuration:commons-configuration:1.6'
498     compile 'org.apache.hadoop:hadoop-core:1.0.4'
500     compile 'com.linkedin.pegasus:r2:1.8.3'
501     compile 'com.linkedin.pegasus:data:1.8.3'
502     compile 'com.linkedin.pegasus:pegasus-common:1.8.3'
504     compile 'com.google.code.typica:typica:1.7.2'
505     compile 'com.sna-projects.krati:krati:0.4.9'
508 eclipse {
509     jdt {
510         // Currently the javac Version of jar is set to 1.5
511         // But @Override works differently between both, so overriding here
512         sourceCompatibility = targetCompatibility = 1.6
513     }
514     classpath {
515         defaultOutputDir = project.file('classes')
516         file {
517             // SourceSets creates multiple src/java in .classpath with varying includes
518             // But eclipse 4.3 is complaining about duplicate classpaths
519             // If contrib root is included instead of the seperate projects, eclipse
520             // expects the package to be different. ( contrib.restclient.test.voldemort.client
521             // versus voldemort.client ). So removing all the src entries and adding the previous
522             // src entries which used to work.
523             whenMerged { classpath ->
524                 classpath.entries.removeAll { entry ->
525                     (entry.kind == 'src' )
526                 }
527             }
528             withXml {
529                 def node = it.asNode()
530                 [
531                     "src/java",
532                     "contrib/ec2-testing/resources",
533                     "contrib/ec2-testing/src/java",
534                     "contrib/ec2-testing/test",
535                     "contrib/hadoop-store-builder/test",
536                     "contrib/hadoop-store-builder/src/java",
537                     "test/unit",
538                     "test/integration",
539                     "test/common",
540                     "test/long",
541                     "example/java",
542                     "contrib/krati/src/java",
543                     "contrib/krati/test",
544                     "contrib/collections/src/java",
545                     "contrib/collections/test",
546                     "contrib/restclient/src/java",
547                     "contrib/restclient/test"
548                 ]
549                 .each{
550                     node.appendNode('classpathentry', [kind: 'src', path: "$it"])
551                 }
552             }
553         }
554     }