forked from linkedin/li-apache-kafka-clients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
235 lines (206 loc) · 6.89 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
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
/*
* Copyright 2017 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/
import javax.xml.bind.DatatypeConverter
import java.security.MessageDigest
import java.util.regex.Pattern
plugins {
id "com.jfrog.artifactory"
id "idea"
}
group = 'com.linkedin.kafka.clients'
project.ext {
gitHash = "unknown"
gitName = "unknown"
pomConfig = {
url "https://github.com/linkedin/li-apache-kafka-clients"
licenses {
license {
name "BSD 2-CLAUSE LICENSE"
url "https://opensource.org/licenses/BSD-2-Clause"
}
}
developers {
developer {
name "Sir Joel Koshy"
email "jjkoshy@yahoo.com"
}
developer {
name "Jiangjie (Becket) Qin"
email "becket.qin@gmail.com"
}
developer {
name "Dong Lin"
email "lindong28@gmail.com"
}
developer {
name "Sean Mccauliff"
email "smccauliff@linkedin.com"
}
}
scm {
url "https://github.com/linkedin/li-apache-kafka-clients"
}
}
liKafkaVersion = "2.0.0.25"
marioVersion = "0.0.29"
}
subprojects {
group = rootProject.group
version = rootProject.version
plugins.withType(JavaPlugin) {
plugins.apply('checkstyle')
repositories {
jcenter()
maven {
url "https://dl.bintray.com/linkedin/maven"
}
}
dependencies {
testCompile 'org.testng:testng:6.11'
testRuntime 'log4j:log4j:1.2.17'
testRuntime 'org.slf4j:slf4j-log4j12:1.7.26'
testRuntime 'org.apache.logging.log4j:log4j-to-slf4j:2.12.0'
}
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
}
compileTestJava {
options.encoding = 'UTF-8'
}
test {
useTestNG()
maxHeapSize = "1024m"
testLogging {
events "started", "passed", "failed", "skipped"
}
}
checkstyle {
configDir = rootProject.file('config/checkstyle')
toolVersion = '8.4'
}
test.dependsOn('checkstyleMain', 'checkstyleTest')
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
assemble.dependsOn ':parseGitInfo' //make sure we have git info before packaging
jar {
doFirst { //for some odd reason this is needed to pick up gitHash
//version embedding at build time
//we create a file called __Versioning__[md5] and set its payload to contain versioning info
//
//the file name is not fixed, but contains an md5 hash of the project group name and version.
//its not fixed so that if multiple libraries are repackaged (think fat/shaded jar) the versioning files
//are unlikely to conflict or get overwritten. the md5 hash part is chosen such that builds are
//"repeatable" - re-running the same build results in the same output. this is nice for incremental builds.
//
//the value contains versioning information for both this module and the entire project it was built as part of.
//
//this information allows us, at runtime, to determine what libraries/versions exist on a given classpath
MessageDigest md = MessageDigest.getInstance("MD5")
md.update(project.group.getBytes("UTF-8"))
md.update(project.name.getBytes("UTF-8"))
md.update(project.version.getBytes("UTF-8"))
byte[] digest = md.digest();
String hash = DatatypeConverter.printHexBinary(digest).toUpperCase()
String versioningFileName = "__Versioning__" + hash
String versioningPayload = "{" +
"\"format\":\"v1\"," +
"\"project\":\"" + rootProject.group + ":" + rootProject.name + ":" + rootProject.version + "\"," +
"\"module\":\"" + project.group + ":" + project.name + ":" + project.version + "\"," +
"\"branch\":\"" + rootProject.gitName + "\"," +
"\"revision\":\"" + rootProject.gitHash + "\"" +
"}"
String outFolder = "${project.buildDir}/resources/main/META-INF/"
mkdir outFolder
file("${outFolder}/${versioningFileName}").text = versioningPayload
}
}
}
}
artifactoryPublish.skip = true
artifactory {
contextUrl = 'https://linkedin.jfrog.io/linkedin'
publish {
repoKey = 'li-apache-kafka-clients'
username = System.getenv('ARTIFACTORY_USER')
password = System.getenv('ARTIFACTORY_KEY')
defaults {
publications ('java')
publishBuildInfo = true
publishArtifacts = true
publishPom = true
publishIvy = true
}
}
clientConfig.setIncludeEnvVars(false)
}
task distributeBuild(type: com.linkedin.gradle.build.DistributeTask) {
dependsOn ':artifactoryPublish', ':li-apache-kafka-clients:artifactoryPublish', ':kafka-test-harness:artifactoryPublish'
}
//wrapper generation task
wrapper {
gradleVersion = '5.2.1'
distributionType = Wrapper.DistributionType.ALL
}
tasks.register("parseGitInfo") {
group = 'Versioning'
description = 'retrieves the current branch/tag name and git hash'
doLast {
def headFile = file("${rootProject.rootDir}/.git/HEAD")
if (!headFile.exists()) {
//we're not a git working copy
logger.warn("${headFile} not found - this doesnt appear to be a git checkout")
rootProject.gitHash = "unknown"
rootProject.gitName = "unknown"
return
}
def contents = headFile.text
//.git/HEAD is either a hash (if detached head) or a ref
def refPattern = Pattern.compile("ref:\\s+(refs/(\\w+)/(.*))\\s+\$")
def matcher = refPattern.matcher(contents)
if (!matcher.matches()) {
rootProject.gitHash = contents.trim()
rootProject.gitName = contents.trim() //use the hash as the branch name
logger.info("git working copy is in detached head mode at revision ${gitHash}")
} else {
def path = matcher.group(1)
def category = matcher.group(2)
def name = matcher.group(3)
def refFile = file("${rootProject.rootDir}/.git/${path}")
if (!refFile.exists()) {
//TODO - add support for packed-refs
throw new IllegalStateException("unable to find ${refFile}")
}
rootProject.gitHash = refFile.text.trim()
rootProject.gitName = name
def type
switch (category) {
case "heads":
type = "branch"
break
case "tags":
type = "tag"
break
default:
logger.warn("unknown ref folder ${category}")
type = "unknown"
break
}
logger.info("git working copy is at ${type} ${rootProject.gitName} at revision ${rootProject.gitHash}")
}
}
}