Merge pull request #178 from arunthirupathi/checkMetadata
[voldemort/jeffpc.git] / build.gradle
blobc3ea99c04d50322fb3b24d2173e534378fbc28e1
1 import java.util.jar.JarEntry;
3 apply plugin: 'java'
4 apply plugin: 'scala'
6 def String getProjectProperty(String propertyName) {
7     String propertyValue = "null"
8     if (hasProperty(propertyName)) {
9         propertyValue = this.properties[propertyName]
10     }
11     else {
12         throw GradleScriptException("PropertyName " + propertyName + " is not defined in properties file")
13     }
14     return propertyValue
16 def projectName = "voldemort"
18 def sourceDir = getProjectProperty('src.dir')
19 def distDir = getProjectProperty('dist.dir')
20 def classesDir = getProjectProperty('classes.dir')
21 def javaDir = getProjectProperty('java.dir')
22 def libDir = getProjectProperty('lib.dir')
23 def resourcesDir = getProjectProperty('resources.dir')
24 def javaDocDir = getProjectProperty('javadoc.dir')
26 def testClassesDir = getProjectProperty('testclasses.dir')
27 def commonTestSrcDir = getProjectProperty('commontestsrc.dir')
28 def unitTestSrcDir = getProjectProperty('unittestsrc.dir')
29 def intTestSrcDir = getProjectProperty('inttestsrc.dir')
30 def longTestSrcDir = getProjectProperty('longtestsrc.dir')
32 def contribClassesDir = getProjectProperty('contrib.classes.dir')
33 def contribRootDir = getProjectProperty('contrib.root.dir')
35 def voldVersion = getProjectProperty('curr.release')
36 def javacVersion = getProjectProperty('javac.version')
37 def scalaVersion = getProjectProperty('scalac.version')
39 //This is the javaCompile variable version. Directly defining 'def version' will override this and cause nightmare
40 version = voldVersion
42 def archiveDirectoryName = projectName + '-' + version
43 def archiveDirectoryPath = distDir + "/" + archiveDirectoryName
45 def deleteDirectoryContents(directory) {
46     project.file(directory).deleteDir()
47     project.file(directory).mkdirs()
50 plugins.withType(JavaPlugin) {
51     println 'java source target compatibility version ' + javacVersion
52     sourceCompatibility = javacVersion
53     targetCompatibility = javacVersion
54     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     }
83     buildTest {
84         java {
85             srcDirs = [
86                 commonTestSrcDir ,
87                 unitTestSrcDir,
88                 intTestSrcDir ,
89                 longTestSrcDir
90             ]
91         }
92         output.classesDir = testClassesDir
93         compileClasspath += sourceSets.main.runtimeClasspath
94     }
95     contrib {
96         java { srcDirs = [contribRootDir]}
97         compileClasspath += sourceSets.main.runtimeClasspath
98         output.classesDir = contribClassesDir
99     }
102 compileJava.dependsOn clean
104 task compileJava.doLast {
105     project.copy {
106         from (javaDir) { exclude '**/*.java','**/*.html','**/*.scala', '**/log4j.properties' }
107         into classesDir
108     }
110     project.copy {
111         from (javaDir) { include 'log4j.properties' }
112         into resourcesDir
113     }
116 compileBuildTestJava.doLast {
117         project.copy {
118             from (commonTestSrcDir) { exclude '**/*.java','**/*.html' }
119             from (unitTestSrcDir) { exclude '**/*.java','**/*.html' }
120             into testClassesDir
121         }
124 compileContribJava.doLast {
125         project.copy {
126             from (contribRootDir + '/ec2-testing/resources')
127             into contribClassesDir
128         }
132 dependencies {
133     compile fileTree(dir: libDir, includes: ['**/*.jar'])
135     buildTestCompile sourceSets.main.output
137     contribCompile sourceSets.main.output
138     contribCompile sourceSets.buildTest.output
139     contribCompile fileTree(dir: contribRootDir, includes: ['**/*.jar'])
142 test{
143     // workingDir = new File(rootDir , "src/");
144     println "working directory is:" + rootDir
145     minHeapSize = "1g"
146     maxHeapSize = "2g"
147     // scanForTestClasses = false
150 task testJar(type: Jar) {
151     dependsOn sourceSets.buildTest.output
152     baseName = projectName + "-test"
153     from sourceSets.buildTest.output
154     destinationDir = project.file(distDir)
157 task voldJar(type:Jar) {
158     baseName = projectName
159     manifest {
160         attributes 'Voldemort-Implementation-Version' : version,
161         'Implementation-Title': 'Voldemort',
162         'Implementation-Version': version,
163         'Implementation-Vendor' :'LinkedIn'
164     }
165     from sourceSets.main.output
166     destinationDir = project.file(distDir)
169 task contribJar(type:Jar) {
170     dependsOn voldJar, testJar, sourceSets.contrib.output
171     baseName = projectName + "-contrib"
172     from sourceSets.contrib.output
173     destinationDir = project.file(distDir)
176 task sourcesJar(type: Jar, dependsOn: classes) {
177     classifier = 'src'
178     from sourceSets.main.java.srcDirs
179     destinationDir = project.file(distDir)
182 artifacts {
183     archives voldJar
184     archives testJar
185     archives contribJar
186     archives sourcesJar
189 clean {
190     project.file(distDir).deleteDir()
191     deleteDirectoryContents(javaDocDir)
194 task copySources (type: Copy) {
195     println 'doing the copy now'
196     from ('.') { include 'bin/**' }
197     from ('.') { include  distDir + '/*.jar'}
198     from ('.') { exclude distDir + '/**' ,'bin/**' , 'build/**', '.git/**' , '.gradle/**' }
199     into archiveDirectoryPath
202 task zip (type: Zip) {
203     dependsOn copySources
204     baseName = projectName
206     from(distDir) {
207         include archiveDirectoryName + '/bin/**'
208         fileMode = 0755
209     }
210     from(distDir) {
211         include archiveDirectoryName + '/**'
212         exclude archiveDirectoryName + '/bin/**'
213     }
215     destinationDir = project.file(distDir)
218 task tar (type: Tar) {
219     dependsOn copySources
220     compression = Compression.GZIP
221     baseName = projectName
222     extension = "tar.gz"
224     from(distDir) {
225         include archiveDirectoryName + '/bin/**'
226         fileMode = 0755
227     }
228     from(distDir) {
229         include archiveDirectoryName + '/**'
230         exclude archiveDirectoryName + '/bin/**'
231     }
233     destinationDir = project.file(distDir)
236 jar.dependsOn contribJar,sourcesJar
237 compileContribJava.dependsOn voldJar
238 copySources.dependsOn jar