-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathbuild.gradle
165 lines (139 loc) · 5.52 KB
/
build.gradle
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
plugins {
id 'java'
id 'idea'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'com.adarshr.test-logger' version '2.1.0'
}
defaultTasks 'build'
group = 'com.airbnb'
description = 'StatsD Support for Kafka Metrics (kafka version: 0.8 and 0.9)'
repositories {
mavenCentral()
maven { url "http://dl.bintray.com/airbnb/jars" }
}
ext {
defaultKafkaVersion = '0.9.0.1'
kafkaVersion = project.getProperties().getOrDefault("kafkaVersion", defaultKafkaVersion)
kafkaVersionsToTest = ['0.8.2.2', '0.9.0.1', '0.10.2.2', '1.1.1', '2.3.1']
testWithKafkaClient = project.getProperties().getOrDefault("testWithKafkaClient", false)
kafkaClientVersionsToTest = ['0.9.0.1', '0.10.2.2', '1.1.1', '2.3.1']
}
dependencies {
compile 'com.indeed:java-dogstatsd-client:2.0.11'
if (testWithKafkaClient) {
compileOnly "org.apache.kafka:kafka-clients:${kafkaVersion}"
} else {
compileOnly "org.apache.kafka:kafka_2.11:${defaultKafkaVersion}"
}
compileOnly 'org.slf4j:slf4j-log4j12:+'
if (testWithKafkaClient) {
testCompile "org.apache.kafka:kafka-clients:${kafkaVersion}"
} else {
testCompile "org.apache.kafka:kafka_2.11:${kafkaVersion}"
}
testCompile 'org.slf4j:slf4j-log4j12:+'
testCompile 'junit:junit:4.11'
testCompile 'org.easymock:easymock:3.2'
testCompile 'org.mockito:mockito-inline:3.5.10'
testCompile 'com.google.guava:guava:29.0-jre'
}
compileJava {
options.setDeprecation true
options.encoding = 'UTF-8'
}
def excludeFromCompile(Task task, Map<String, List<String>> excludeMap) {
excludeMap.each { path, filesToExclude ->
filesToExclude.each { fileToExclude ->
task.exclude(path + fileToExclude + ".java")
}
}
}
if (testWithKafkaClient) {
def srcExcludes = [
"com/airbnb/kafka/kafka08/": ["**/*"],
"com/airbnb/metrics/": ["ExcludeMetricPredicate", "MetricNameFormatter", "Parser", "ParserForNoTag", "ParserForTagInMBeanName", "StatsDReporter"]
]
def testExcludes = [
"com/airbnb/kafka/kafka08/": ["**/*"],
"com/airbnb/metrics/": ["DimensionTest", "ExcludeMetricPredicateTest", "MetricNameFormatterTest", "ParserTest", "StatsDReporterTest"]
]
excludeFromCompile(compileJava, srcExcludes)
excludeFromCompile(compileTestJava, testExcludes)
}
configurations {
// manually excludes some unnecessary dependencies
compile.exclude module: 'zookeeper'
compile.exclude module: 'zkclient'
compile.exclude module: 'javax'
compile.exclude module: 'jline'
compile.exclude module: 'jms'
compile.exclude module: 'jmxri'
compile.exclude module: 'jmxtools'
compile.exclude module: 'mail'
}
shadowJar {
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
exclude 'META-INF/maven/*'
}
def testKafkaVersionTasks = []
for (kafkaVersion in kafkaVersionsToTest) {
String kafkaVersionUnderscored = kafkaVersion.replace('.', '_')
def task = tasks.create(name: "testWithKafkaCore_${kafkaVersionUnderscored}", type: GradleBuild) {
// Changing `buildName` is a workaround for a Gradle issue when trying to run
// the aggregate task `testWithAllSupportedKafkaVersions`.
// See the following issues:
// 1. https://github.com/gradle/gradle/issues/11301
// 2. https://github.com/gradle/gradle/issues/12872
buildName = project.getName() + "-kafka_" + kafkaVersionUnderscored
buildFile = './build.gradle'
tasks = ['test']
startParameter.projectProperties = [kafkaVersion: "${kafkaVersion}"]
group = 'Verification'
description = "Runs the unit tests with Kafka core version ${kafkaVersion}"
}
if (!testKafkaVersionTasks.isEmpty()) {
task.mustRunAfter(testKafkaVersionTasks.last())
}
testKafkaVersionTasks.add(task)
}
test.doFirst {
println "Running tests with Kafka version ${kafkaVersion}"
println "Testing with Kafka clients: ${testWithKafkaClient}"
}
task testWithAllSupportedKafkaCoreVersions {
group = 'Verification'
description = "Runs the unit tests with all supported Kafka core versions: ${kafkaVersionsToTest}"
dependsOn(testKafkaVersionTasks)
}
def testKafkaClientVersionTasks = []
for (kafkaVersion in kafkaClientVersionsToTest) {
String kafkaVersionUnderscored = kafkaVersion.replace('.', '_')
def task = tasks.create(name: "testWithKafkaClient_${kafkaVersionUnderscored}", type: GradleBuild) {
// Changing `buildName` is a workaround for a Gradle issue when trying to run
// the aggregate task `testWithAllSupportedKafkaVersions`.
// See the following issues:
// 1. https://github.com/gradle/gradle/issues/11301
// 2. https://github.com/gradle/gradle/issues/12872
buildName = project.getName() + "-kafka-clients_" + kafkaVersionUnderscored
buildFile = './build.gradle'
tasks = ['test']
startParameter.projectProperties = [kafkaVersion: "${kafkaVersion}", testWithKafkaClient: true]
group = 'Verification'
description = "Runs the unit tests with Kafka client version ${kafkaVersion}"
}
if (!testKafkaClientVersionTasks.isEmpty()) {
task.mustRunAfter(testKafkaClientVersionTasks.last())
}
testKafkaClientVersionTasks.add(task)
}
task testWithAllSupportedKafkaClientVersions {
group = 'Verification'
description = "Runs the unit tests with all supported Kafka client versions: ${kafkaClientVersionsToTest}"
dependsOn(testKafkaClientVersionTasks)
}
task testWithAllSupportedKafkaVersions {
group = 'Verification'
description = "Runs the unit tests with all supported Kafka core and client versions: ${kafkaVersionsToTest}"
dependsOn(testWithAllSupportedKafkaCoreVersions, testWithAllSupportedKafkaClientVersions)
}