-
Notifications
You must be signed in to change notification settings - Fork 51
/
build.gradle
252 lines (225 loc) · 10.8 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
id "me.champeau.jmh" version "0.6.6" apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'io.freefair.lombok' version '8.2.2' apply false
}
subprojects {
// We can't use plugins {} syntax in subprojects as of Gradle 6.x
apply plugin: 'idea'
apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'maven-publish'
apply plugin: 'signing'
// !!!Do not reverse order of these two plugins (jmh and shadow) loading!!!
// jmh plugin changes its behavior by whether the shadow plugin is loaded or not, and with shadow plugin
// it does not work well by failing to generate an jmh JAR to be executed.
// https://github.com/melix/jmh-gradle-plugin/blob/c17c89c8fed6d655678aac16ecd5b683ea7fc8b5/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy#L77
apply plugin: 'me.champeau.jmh'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'io.freefair.lombok'
group = "com.linecorp.decaton"
version = "${version}" + (snapshot.toBoolean() ? "-SNAPSHOT" : "")
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
ext {
// Freezing this to 1.X until https://github.com/spring-projects/spring-boot/issues/12649 is resolved
slf4jVersion = "1.7.36"
protobufVersion = "3.22.3"
kafkaVersion = "3.2.3"
micrometerVersion = "1.12.4"
micrometerTracingVersion = "1.2.4"
lombokVersion = "1.18.30"
junitVersion = "5.10.0"
hamcrestVersion = "2.2"
isReleaseVersion = !version.endsWith('-SNAPSHOT')
shadeAllDependencies = false // Whether this project should results uber jar or not
noPublish = false // Whether to publish this artifact to maven or not
publishOnlyLocal = false // Whether to publish this artifact to local maven only (no effect if noPublish = true)
relocatePb = true // Whether to relocate package name of protocol buffers classes
}
// need override because gradle-lombok plugin brings outdated lombok version
lombok {
version = "$lombokVersion"
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
configurations {
shade
api.extendsFrom(shade)
itImplementation.extendsFrom(implementation)
}
dependencies {
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
// Likely be used for most modules
testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion"
testImplementation "org.mockito:mockito-core:4.11.0"
testImplementation "org.mockito:mockito-junit-jupiter:4.11.0"
itImplementation "org.junit.jupiter:junit-jupiter:$junitVersion"
}
sourceSets.create('it') {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
compileClasspath += sourceSets.testFixtures.output
runtimeClasspath += sourceSets.testFixtures.output
}
task integrationTest(type: Test) {
testClassesDirs = sourceSets.it.output.classesDirs
classpath = sourceSets.it.runtimeClasspath
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
showStandardStreams false
}
def testJavaVersion = findProperty("test.java.major.version")
if (testJavaVersion != null) {
// https://docs.gradle.org/8.5/userguide/toolchains.html#toolchains_for_tasks
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaVersion)
}
}
}
afterEvaluate {
if (!noPublish) {
publishing {
repositories {
maven {
if (isReleaseVersion) {
url("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else {
url("https://oss.sonatype.org/content/repositories/snapshots/")
}
credentials {
username findProperty("sonatypeUsername")
password findProperty("sonatypePassword")
}
}
}
publications {
mavenJava(MavenPublication) {
artifactId = rootProject.name + '-' + project.name
// Create a custom publication that ships shadow jar (along with few other jars) with
// maven pom which properly declares necessary dependencies.
// We can't simply do `from components.java`.
// The java component contains non-shaded jar, so its jar doesn't contain relocated
// protobuf-java.
// We can't modify `artifacts` of java component either because it is prevented by
// gradle: https://github.com/gradle/gradle/blob/8d6c7361264fdfbe75feb113501758c0deeca5f4/subprojects/maven/src/main/java/org/gradle/api/publish/maven/internal/publication/DefaultMavenPublication.java#L815
// The shadow plugin provides `shadow` configuration, but all these dependencies are
// mapped to "runtime" scope so just `components.shadow` doesn't work either.
// Apparently there's no API for obtaining dependency list from one component and
// bring it to another component, so customizing maven pom directly is the only option.
artifacts = [artifact(source: shadowJar, classifier: null),
artifact(source: sourcesJar),
artifact(source: javadocJar)]
afterEvaluate {
pom.withXml {
def rootNode = asNode()
def depListNode = null
if (rootNode.dependencies) {
depListNode = rootNode.dependencies.get(0)
} else {
depListNode = new Node(rootNode, 'dependencies')
}
if (!shadeAllDependencies) {
def excludeDeps = new HashSet<>(project.configurations.shade.allDependencies)
for (config in [["api", "compile"], ["implementation", "runtime"]]) {
project.configurations.getByName(config[0]).allDependencies.each { dep ->
if (!excludeDeps.add(dep)) {
return;
}
def depNode = new Node(depListNode, 'dependency')
depNode.appendNode('groupId', dep.group)
def prefix = dep.group == 'com.linecorp.decaton' && !dep.name.startsWith('decaton-') ? 'decaton-' : ''
depNode.appendNode('artifactId', prefix + dep.name)
depNode.appendNode('version', dep.version)
depNode.appendNode('scope', config[1])
}
}
}
}
}
pom {
name = 'Decaton'
description = 'High throughput asynchronous task processing on Apache Kafka'
url = 'https://github.com/line/decaton'
scm {
url = '[email protected]:line/decaton.git'
connection = 'scm:git:[email protected]:line/decaton.git'
developerConnection = 'scm:git:[email protected]:line/decaton.git'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0'
}
}
developers {
developer {
name = 'Decaton developers'
email = '[email protected]'
}
}
}
}
}
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
}
}
}
shadowJar {
archiveClassifier.set('shadow')
afterEvaluate {
if (!shadeAllDependencies) {
// Shade only dependencies which are declared to be shaded explicitly.
// By this line, all dependencies declared with `api` or `implementation` will be added as
// external dependencies and their classes aren't be merged into resulting shadow jar.
configurations = [project.configurations.shade]
}
if (relocatePb) {
// Relocate protobuf package prefixing unique identifier `com.linecorp.decaton`
relocate "com.google.protobuf.", "com.linecorp.decaton.com.google.protobuf."
}
}
}
tasks.withType(PublishToMavenRepository) {
onlyIf {
!publishOnlyLocal
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
javadoc {
source = delombok
options.encoding = 'UTF-8'
options.locale = 'en_US'
}
task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
from javadoc
}
build.dependsOn(javadoc)
}