use maven central for gradle dependencies
[voldemort/jeffpc.git] / build.gradle
blob1e69365cfdd6a416b69508759b62cd315ed1d189
1 import java.util.jar.JarEntry;
3 apply plugin: 'java'
4 apply plugin: 'scala'
5 apply plugin: 'idea'
6 apply plugin: 'eclipse'
8 def String getProjectProperty(String propertyName) {
9     String propertyValue = "null"
10     if (hasProperty(propertyName)) {
11         propertyValue = this.properties[propertyName]
12     }
13     else {
14         throw GradleScriptException("PropertyName " + propertyName + " is not defined in properties file")
15     }
16     return propertyValue
18 def projectName = "voldemort"
20 def sourceDir = getProjectProperty('src.dir')
21 def distDir = getProjectProperty('dist.dir')
22 def classesDir = getProjectProperty('classes.dir')
23 def javaDir = getProjectProperty('java.dir')
24 def privateLibDir = getProjectProperty('private.lib.dir')
25 def resourcesDir = getProjectProperty('resources.dir')
26 def javaDocDir = getProjectProperty('javadoc.dir')
28 def voldTestClassesDir = getProjectProperty('testclasses.dir')
30 def commonTestSrcDir = getProjectProperty('commontestsrc.dir')
31 def unitTestSrcDir = getProjectProperty('unittestsrc.dir')
32 def intTestSrcDir = getProjectProperty('inttestsrc.dir')
33 def longTestSrcDir = getProjectProperty('longtestsrc.dir')
35 def contribClassesDir = getProjectProperty('contrib.classes.dir')
36 def contribRootDir = getProjectProperty('contrib.root.dir')
38 def voldVersion = getProjectProperty('curr.release')
39 def javacVersion = getProjectProperty('javac.version')
40 def scalaVersion = getProjectProperty('scalac.version')
42 //This is the javaCompile variable version. Directly defining 'def version' will override this and cause nightmare
43 version = voldVersion
45 def archiveDirectoryName = projectName + '-' + version
46 def archiveDirectoryPath = distDir + "/" + archiveDirectoryName
48 def deleteDirectoryContents(directory) {
49     project.file(directory).deleteDir()
50     project.file(directory).mkdirs()
53 println 'java source target compatibility version ' + javacVersion
54 sourceCompatibility = javacVersion
55 targetCompatibility = javacVersion
56 compileJava.options.debug = true
59 tasks.withType(ScalaCompile) {
60     scalaCompileOptions.useAnt = false
63 repositories {
64     mavenCentral()
65     flatDir { dirs privateLibDir }
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 + sourceSets.test.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 task testJar(type: Jar) {
133     baseName = projectName + "-test"
134     from sourceSets.test.output
135     destinationDir = project.file(distDir)
138 task voldJar(type:Jar) {
139     baseName = projectName
140     manifest {
141         attributes 'Voldemort-Implementation-Version' : version,
142         'Implementation-Title': 'Voldemort',
143         'Implementation-Version': version,
144         'Implementation-Vendor' :'LinkedIn'
145     }
146     from sourceSets.main.output
147     destinationDir = project.file(distDir)
150 task contribJar(type:Jar) {
151     dependsOn voldJar, testJar, sourceSets.contrib.output
152     baseName = projectName + "-contrib"
153     from sourceSets.contrib.output
154     destinationDir = project.file(distDir)
157 task srcJar(type: Jar, dependsOn: classes) {
158     classifier = 'src'
159     from sourceSets.main.java.srcDirs
160     destinationDir = project.file(distDir)
163 artifacts {
164     archives voldJar
165     archives testJar
166     archives contribJar
167     archives srcJar
170 clean {
171     delete(distDir)
172     delete('lib')
173     doLast { deleteDirectoryContents(javaDocDir) }
176 task copySources (type: Copy) {
177     from ('.') { include 'bin/**' }
178     from ('.') { include  distDir + '/*.jar'}
179     from ('.') { exclude distDir + '/**' ,'bin/**' , 'build/**', '.git/**' , '.gradle/**' }
180     into archiveDirectoryPath
183 task zip (type: Zip) {
184     dependsOn copySources
185     baseName = projectName
187     from(distDir) {
188         include archiveDirectoryName + '/bin/**'
189         fileMode = 0755
190     }
191     from(distDir) {
192         include archiveDirectoryName + '/**'
193         exclude archiveDirectoryName + '/bin/**'
194     }
196     destinationDir = project.file(distDir)
199 task tar (type: Tar) {
200     dependsOn copySources
201     compression = Compression.GZIP
202     baseName = projectName
203     extension = "tar.gz"
205     from(distDir) {
206         include archiveDirectoryName + '/bin/**'
207         fileMode = 0755
208     }
209     from(distDir) {
210         include archiveDirectoryName + '/**'
211         exclude archiveDirectoryName + '/bin/**'
212     }
214     destinationDir = project.file(distDir)
217 task copyDeps(type: Copy) {
218     from  {configurations.compile  }
219     into "lib"
223 jar.dependsOn contribJar,srcJar, copyDeps
224 compileContribJava.dependsOn voldJar
225 copySources.dependsOn jar
227 tasks.withType(Test) {
228     // ant restarts jvm for each tests, If not restarted the test runs into outOfMemory even
229     // if you set the JVM to 8gb. On inspecting most of the space is consumed by int[] of
230     // Histogram in the NioSelectorManager. I believe this could be explained by
231     // creating lots of client factory which creates lot of NIO threads. Did not proceed
232     // further as I will be maintaining compatbility with ant. Also if you dont fork for each
233     // tests JMX bean related tests will fail.
235     // Do not set the max parallelism as there are tests that uses the same port and will
236     // run into bind exceptions.
237     maxHeapSize = "2g"
238     forkEvery = 1
241     // If ignoreFailures is not set, then merged reports will not be generated
242     // Gradle aborts further tasks on test failure. so if you run junitAll
243     // which runs 3 tests, reports task will never be run on failure cases.
244     ignoreFailures = true
245     //ignoreFailures = gradle.startParameter.continueOnFailure
247     useJUnit()
249     testLogging {
250         events "passed", "skipped", "failed"
251         exceptionFormat = 'full'
252     }
254     afterTest { test, result ->
255         logger.lifecycle("testFinished: $test, result: $result.resultType")
256     }
258     doFirst {
259       def classesSize = candidateClassFiles.files.size()
260       logger.lifecycle("{} starts executing {} test classes {}",
261           path, classesSize, classesSize > 0? "(" + candidateClassFiles.files*.name[0] + ", ...)" : "")
262     }
264     //all standard error messages from tests will get routed to 'DEBUG' level messages.
265     //logging.captureStandardError(LogLevel.DEBUG)
266     //all standard output messages from tests will get routed to 'DEBUG' level messages.
267     //logging.captureStandardOutput(LogLevel.DEBUG)
269     //Set reasonable defaults for reports location
270     reports.html.destination = file("$project.buildDir/reports/$name")
271     reports.junitXml.destination = file("$project.buildDir/$name-results")
273     //Set reasonable defaults classpath and classes dir. They can be reconfigured in an individual task.
274     it.testClassesDir = sourceSets.test.output.classesDir
275     classpath = sourceSets.test.runtimeClasspath
278 task junit(dependsOn: test)
280 Collection<String> testClassesFrom(String dir, String include = '**/*Test.*') {
281   //take all *Test.java files found in given dir, make the path relative and replace .java with .class
282   fileTree(dir: dir, includes: [include]).collect { it.absolutePath.replaceAll(file(dir).absolutePath + "/", "").replaceAll(".java\$", ".class")}
285 test {
286     description = "Runs acceptance tests"
287     include testClassesFrom(unitTestSrcDir)
290 task junitLong(type: Test) {
291     description = "Runs long junit tests"
292     include testClassesFrom(longTestSrcDir)
295 task junitRebalance(type: Test) {
296   include testClassesFrom(unitTestSrcDir, '**/*Rebalance*Test.java')
299 task junitRebalanceLong(type: Test) {
300   include testClassesFrom(longTestSrcDir, '**/*Rebalance*Test.java')
303 task contribJunit(type: Test) {
304     description = "Run contrib junit tests except EC2 and Krati tests."
305     it.testClassesDir = file(contribClassesDir)
307     exclude '**/*PerformanceTest.class'
308     exclude '**/*RemoteTest.class'
309     exclude '**/Ec2*Test.class'
310     exclude '**/Krati*Test.class'
311     exclude '**/HadoopStoreBuilder*Test.class'
313     classpath += sourceSets.contrib.runtimeClasspath + sourceSets.contrib.output
316 task junitAll(type: TestReport) {
317     reportOn test, junitLong, contribJunit
318     destinationDir = file("$project.buildDir/reports/$name")
321 task aggregatedJunit(type: TestReport) {
322 destinationDir = file("$project.buildDir/reports/$name")
325 tasks.withType(Test) {
326   finalizedBy aggregatedJunit
327   doLast {
328     aggregatedJunit.reportOn it.binResultsDir
329   }
332 task wrapper(type: Wrapper) {
333     gradleVersion = '1.12'
337 dependencies {
338     // Avro serialization format
339     compile 'org.apache.avro:avro:1.4.0'
341     // INTERNAL_LIBS azkaban version not found
342     // azkaban-common-0.05.jar
344     // INTERNAL_LIBS Used for tomcat deployment, not sure if anyone uses it
345     // catalina-ant.jar , version not found in maven central
347     // coders decoders containing the Base64,binary encoding
348     compile 'commons-codec:commons-codec:1.4'
350     // TRANSITIVE_DEPENDENCY Contrib jar depends on commons-configuration-1.6.jar
351     // commons-configuration instead depends on commons-collection
352     //compile 'commons-collections:commons-collections:3.2.1'
354     // Used by MySql storage engine classes
355     // The jar supports database connection pooling
356     compile 'commons-dbcp:commons-dbcp:1.2.2'
358     // commons io is used at many places
359     // IOUtils, FileUtils and ByteArrayOutputStream
360     compile 'commons-io:commons-io:1.4'
362     // LZF compression strategy for store and tests.
363     compile 'com.ning:compress-lzf:0.9.1'
365     // TRANSITIVE_DEPENDENCY tusk jar internally uses gson.
366     compile 'com.google.code.gson:gson:2.2.4'
368     // Used all over the place for collections
369     compile 'com.google.guava:guava:14.0.1'
371     // used for readonly store hdfs fetcher.
372     compile 'org.apache.hadoop:hadoop-auth:2.0.5-alpha'
374     // used at lots of places. Seems like there is some overlap between httpclient and core, but not clear
375     compile 'org.apache.httpcomponents:httpclient:4.1.2'
377     // contains both http server and client functionalities. Used for HttpResponse but could be used at more places.
378     compile 'org.apache.httpcomponents:httpcore:4.1.2'
380     // JSON mapping library from Java Objects to JSON
381     compile 'org.codehaus.jackson:jackson-mapper-asl:1.4.0'
383     // JSON processing library
384     compile 'org.codehaus.jackson:jackson-core-asl:1.4.0'
386     // Used for reading XML files and Document.
387     compile 'jdom:jdom:1.1'
389     // je- BDB je 5.0.88 is not available in maven central repository.
390     // Could be possibly found in oracle maven repository, but not sure
391     /*
392     groupId>com.sleepycat</groupId>
393           <artifactId>je</artifactId>
394           <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     // Used for unit tests and other automated testing
482     testCompile 'junit:junit:4.6'
484     // Mockito is written by our beloved friend Szczepan Faber :)
485     // Mocking framework used in some tests
486     testCompile 'org.mockito:mockito-all:1.8.5'
488     contribCompile sourceSets.main.output
489     contribCompile sourceSets.test.output
491     // declaring contribCompile dependencies as compile dependencies
492     // otherwise while copying dependencies to lib directory
493     // conflict resolution is not done properly across sourceSets
494     // and we end up with 2 versions of few jars like ( log4j, servlet etc. )
495     compile 'commons-configuration:commons-configuration:1.6'
496     compile 'org.apache.hadoop:hadoop-core:1.0.4'
498     compile 'com.linkedin.pegasus:r2:1.8.3'
499     compile 'com.linkedin.pegasus:data:1.8.3'
500     compile 'com.linkedin.pegasus:pegasus-common:1.8.3'
502     compile 'com.google.code.typica:typica:1.7.2'
503     compile 'com.sna-projects.krati:krati:0.4.9'