aboutsummaryrefslogtreecommitdiff
path: root/bigtop-bigpetstore/bigpetstore-mapreduce/build.gradle
blob: 4bf5ce7dbe615b5e1318b0d08b8986d89eb9c383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
apply plugin: "java"
apply plugin: "eclipse"
// TODO add idea module config.
apply plugin: "idea"
apply plugin: "scala"
apply plugin: 'com.github.johnrengelman.shadow'

buildscript {
  repositories { jcenter() }
  dependencies {
    classpath 'com.github.jengelman.gradle.plugins:shadow:1.0.2'
  }
}

// Read the groupId and version properties from the "parent" bigtop project.
// It would be better if there was some better way of doing this. Howvever,
// at this point, we have to do this (or some variation thereof) since gradle
// projects can't have maven projects as parents (AFAIK. If there is a way to do it,
// it doesn't seem to be well-documented).
def setProjectProperties() {
    Node xml = new XmlParser().parse("../../pom.xml")
    group = xml.groupId.first().value().first()
    version = xml.version.first().value().first()
}

setProjectProperties()
description = """"""

// We are using 1.7 as gradle can't play well when java 8 and scala are combined.
// There is an open issue here: http://issues.gradle.org/browse/GRADLE-3023
// There is talk of this being resolved in the next version of gradle. Till then,
// we are stuck with java 7. But we do have scala if we want more syntactic sugar.
sourceCompatibility = 1.7
targetCompatibility = 1.7

// Specify any additional project properties.
ext {
    slf4jVersion = "1.7.5"
    guavaVersion = "15.0"
    datanucleusVersion = "3.2.2"
    datanucleusJpaVersion = "3.2.1"
    bonecpVersion = "0.8.0.RELEASE"
    derbyVersion = "10.10.1.1"

    // from horton-works repo. They compile mahout-core against hadoop2.x. These
    // mahout is compiled against 2.4.0
    hadoopVersion = "2.4.0.2.1.2.0-402"
    mahoutVersion = "0.9.0.2.1.2.0-402"
}

repositories {
    mavenCentral()
    maven {
        url "http://repo.hortonworks.com/content/repositories/releases/"
    }
}

tasks.withType(AbstractCompile) {
    options.encoding = 'UTF-8'
    options.compilerArgs << "-Xlint:all"
}

tasks.withType(ScalaCompile) {
    // Enables incremental compilation.
    // http://www.gradle.org/docs/current/userguide/userguide_single.html#N12F78
    scalaCompileOptions.useAnt = false
}

tasks.withType(Test) {
    testLogging {
        // Uncomment this if you want to see the console output from the tests.
        // showStandardStreams = true
        events "passed", "skipped", "failed"
        // show standard out and standard error of the test JVM(s) on the console
        //showStandardStreams = true
    }
}

test {
    exclude "**/*TestPig.java", "**/*TestHiveEmbedded.java", "**/*TestCrunch.java", "**/*TestPetStoreTransactionGeneratorJob.java"
}

// Create a separate source-set for the src/integrationTest set of classes. The convention here
// is that gradle will look for a directory with the same name as that of the specified source-set
// under the 'src' directory. So, in this case, it will look for a directory named 'src/integrationTest'
// since the name of the source-set is 'integrationTest'
sourceSets {
    main {
        java.srcDirs = [];
        scala.srcDirs = ["src/main/scala", "src/main/java"]
    }
    // The main and test source-sets are configured by both java and scala plugins. They contain
    // all the src/main and src/test classes. The following statements make all of those classes
    // available on the classpath for the integration-tests, for both java and scala.
    integrationTest {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
        }
        scala {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
        }
    }
}

// Creating a source-set automatically add a couple of corresponding configurations (when java/scala
// plugins are applied). The convention for these configurations is <sourceSetName>Compile and
// <sourceSetName>Runtime. The following statements declare that all the dependencies from the
// testCompile configuration will now be available for integrationTestCompile, and all the
// dependencies (and other configuration that we might have provided) for testRuntime will be
// available for integrationTestRuntime. For ex. the testCompile configuration has a dependency on
// jUnit and scalatest. This makes them available for the integration tests as well.
configurations {
    integrationTestCompile {
        extendsFrom testCompile
    }

    integrationTestRuntime {
        extendsFrom integrationTestCompile, testRuntime
    }
}

// To see the API that is being used here, consult the following docs
// http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
def updateDependencyVersion(dependencyDetails, dependencyString) {
    def parts = dependencyString.split(':')
    def group = parts[0]
    def name = parts[1]
    def version = parts[2]
    if (dependencyDetails.requested.group == group
            && dependencyDetails.requested.name == name) {
        dependencyDetails.useVersion version
    }
}

def setupPigIntegrationTestDependencyVersions(dependencyResolveDetails) {
    // This is the way we override the dependencies.
    updateDependencyVersion dependencyResolveDetails, "joda-time:joda-time:2.2"
}

def setupCrunchIntegrationTestDependencyVersions(dependencyResolveDetails) {
    // Specify any dependencies that you want to override for crunch integration tests.
}

def setupMahoutIntegrationTestDependencyVersions(dependencyResolveDetails) {
    // Specify any dependencies that you want to override for mahout integration tests.
}


task integrationTest(type: Test, dependsOn: test) {

    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath

    if(!project.hasProperty('ITProfile')) {
        // skip integration-tests if no profile has been specified.
        integrationTest.onlyIf { false }
        return;
    }

    def patternsToInclude
    def dependencyConfigClosure
    def skipDependencyUpdates = false
    // Select the pattern for test classes that should be executed, and the dependency
    // configuration function to be called based on the profile name specified at the command line.
    switch (project.ITProfile) {
        case "pig":
            patternsToInclude = "*PigIT*"
            dependencyConfigClosure = { setupPigIntegrationTestDependencyVersions(it) }

            //In pig integration tests, the custom pig script seems to have high
            //memory requirements.
            minHeapSize = "1000m"
            maxHeapSize = "4000m"
            // set JVM arguments for the test JVM(s)
            jvmArgs '-XX:MaxPermSize=256m'
            break
        case "crunch":
            patternsToInclude = "*CrunchIT*"
            dependencyConfigClosure = { setupCrunchIntegrationTestDependencyVersions(it) }
            break
        case "mahout":
            patternsToInclude = "*MahoutIT*"
            dependencyConfigClosure = { setupMahoutIntegrationTestDependencyVersions(it) }
            break
        // skip integration-tests if the passed in profile-name is not valid
        default: integrationTest.onlyIf { false }; return
    }


    filter { includeTestsMatching patternsToInclude }

    // This is the standard way gradle allows overriding each specific dependency.
    // see: http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
    project.configurations.all {
        resolutionStrategy {
            eachDependency {
                dependencyConfigClosure(it)
            }
        }
    }
}

dependencies {
    compile "org.kohsuke:graphviz-api:1.0"
    compile "org.apache.crunch:crunch-core:0.9.0-hadoop2"
    compile "com.jolbox:bonecp:${project.bonecpVersion}"
    compile "org.apache.derby:derby:${project.derbyVersion}"
    compile "com.google.guava:guava:${project.guavaVersion}"
    compile "commons-lang:commons-lang:2.6"
    compile "joda-time:joda-time:2.3"
    compile "org.apache.commons:commons-lang3:3.1"
    compile "com.google.protobuf:protobuf-java:2.5.0"
    compile "commons-logging:commons-logging:1.1.3"
    compile "com.thoughtworks.xstream:xstream:+"
    compile "org.apache.lucene:lucene-core:+"
    compile "org.apache.lucene:lucene-analyzers-common:+"
    compile "org.apache.solr:solr-commons-csv:3.5.0"

    compile group: "org.apache.pig", name: "pig", version: "0.12.0", classifier:"h2"
    compile "org.slf4j:slf4j-api:${project.slf4jVersion}"
    compile "log4j:log4j:1.2.12"
    compile "org.slf4j:slf4j-log4j12:${project.slf4jVersion}"
    compile "org.datanucleus:datanucleus-core:${project.datanucleusVersion}"
    compile "org.datanucleus:datanucleus-rdbms:${project.datanucleusJpaVersion}"
    compile "org.datanucleus:datanucleus-api-jdo:${project.datanucleusJpaVersion}"
    compile "org.datanucleus:datanucleus-accessplatform-jdo-rdbms:${project.datanucleusJpaVersion}"
    compile group: "org.apache.mrunit", name: "mrunit", version: "1.0.0", classifier:"hadoop2"

    compile "org.jfairy:jfairy:0.2.4"

    // from horton-works repo. They compile mahout-core against hadoop2.x
    compile "org.apache.hadoop:hadoop-client:${hadoopVersion}"
    compile "org.apache.mahout:mahout-core:${mahoutVersion}"

    compile 'org.scala-lang:scala-library:2.11.0'

    testCompile "junit:junit:4.11"
    testCompile "org.hamcrest:hamcrest-all:1.3"
    testCompile "org.scalatest:scalatest_2.11:2.1.7"
}

configurations {
    hadoopClusterRuntime {
	    // extendsFrom integrationTestRuntime
	    if(project.hasProperty('for-cluster')) {
		    excludeRules += [getGroup: { 'org.apache.crunch' }, getModule: { 'crunch-core' } ] as ExcludeRule
		    excludeRules += [getGroup: { 'org.apache.pig' }, getModule: { 'pig' } ] as ExcludeRule
		    excludeRules += [getGroup: { 'org.apache.mahout' }, getModule: { 'mahout-core' } ] as ExcludeRule
		    excludeRules += [getGroup: { 'org.apache.hadoop' }, getModule: { 'hadoop-client' } ] as ExcludeRule
		}
    }
}

task listJars << {
    configurations.shadow.each { println it.name }
}

def copyDependencyJarsForHadoopCluster() {
    copy {
        from configurations.hadoopClusterRuntime
        into 'build/libs'
    }
}

build {
    doLast {
        copyDependencyJarsForHadoopCluster()
    }
}

eclipse {
    classpath {
        // Add the dependencies and the src dirs for the integrationTest source-set to the
        // .classpath file that will be generated by the eclipse plugin.
        plusConfigurations += [configurations.integrationTestCompile]
        // Comment out the following two lines if you want to generate an eclipse project quickly.
        downloadSources = true
        downloadJavadoc = false
    }
}