-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle
334 lines (299 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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import com.github.spotbugs.snom.SpotBugsTask
import io.github.gradlenexus.publishplugin.InitializeNexusStagingRepository
plugins {
id 'java-library'
id 'distribution'
id 'jacoco'
id 'maven-publish'
id 'pmd'
id 'signing'
id 'com.github.spotbugs' version '5.0.12'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
id 'org.unbroken-dome.test-sets' version '4.0.0'
}
ext {
kafkaVersion = '3.5.1'
solaceJavaAPIVersion = '10.22.0'
isSnapshot = project.version.endsWith('-SNAPSHOT')
}
repositories {
mavenLocal()
mavenCentral()
}
sourceSets {
main {
java {
srcDir "${buildDir}/generated/java" // add generated sources as additional source directory
}
}
}
testSets {
integrationTest
}
dependencies {
integrationTestImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
integrationTestImplementation 'org.junit-pioneer:junit-pioneer:1.5.0'
integrationTestImplementation 'org.mockito:mockito-junit-jupiter:3.12.4'
integrationTestImplementation 'org.testcontainers:testcontainers:1.16.0'
integrationTestImplementation 'org.testcontainers:junit-jupiter:1.16.0'
integrationTestImplementation 'org.testcontainers:kafka:1.16.0'
integrationTestImplementation 'org.testcontainers:toxiproxy:1.16.0'
integrationTestImplementation 'com.solace.test.integration:pubsubplus-junit-jupiter:1.1.0'
integrationTestImplementation 'org.slf4j:slf4j-api:1.7.32'
integrationTestImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.16.0'
integrationTestImplementation 'org.apache.commons:commons-configuration2:2.6'
integrationTestImplementation 'commons-beanutils:commons-beanutils:1.9.4'
integrationTestImplementation 'com.google.code.gson:gson:2.3.1'
integrationTestImplementation 'commons-io:commons-io:2.4'
integrationTestImplementation 'com.squareup.okhttp3:okhttp:4.9.1'
integrationTestImplementation "org.apache.kafka:kafka-clients:$kafkaVersion"
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.mockito:mockito-junit-jupiter:3.12.4'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.16.0'
implementation "org.apache.kafka:connect-api:$kafkaVersion"
implementation "com.solacesystems:sol-jcsmp:$solaceJavaAPIVersion"
implementation "org.slf4j:slf4j-api:1.7.36"
}
pmd {
consoleOutput = true
toolVersion = '6.49.0'
rulesMinimumPriority = 2
sourceSets = [sourceSets.main]
}
spotbugs {
effort 'max'
reportLevel 'high' // Decrease to medium once medium errors are fixed
}
spotbugsIntegrationTest {
enabled = false
}
task('jacocoFullReport', type: JacocoReport) {
description 'Generates code coverage report for all tests.'
executionData tasks.withType(Test)
sourceSets sourceSets.main
reports {
xml.required = true
}
}
task('prepDistForIntegrationTesting') {
dependsOn assembleDist
doLast {
copy {
from zipTree(file(distsDirectory).listFiles().findAll {
it.name.endsWith("-${project.version}.zip")
}[0])
into sourceSets.integrationTest.resources.srcDirs[0]
}
copy {
from zipTree(file(distsDirectory).listFiles().findAll {
it.name.endsWith("-${project.version}.zip")
}[0])
into sourceSets.integrationTest.output.resourcesDir
}
}
}
project.integrationTest {
useJUnitPlatform()
outputs.upToDateWhen { false }
dependsOn prepDistForIntegrationTesting
shouldRunAfter test
afterSuite { desc, result ->
if (!desc.parent)
println("${result.resultType} " +
"(${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped)")
}
}
project.test {
useJUnitPlatform()
}
tasks.withType(SpotBugsTask) {
reports {
sarif {
enabled = true
}
}
}
// Workaround to generate Sarif report
// Based off https://github.com/gradle/gradle/blob/v6.9.1/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/internal/PmdInvoker.groovy
task('pmdMainSarif') {
PmdExtension extension = project.extensions.getByType(PmdExtension)
dependsOn classes
outputs.dir extension.getReportsDir()
doLast {
ant.taskdef(name: 'pmd',
classname: 'net.sourceforge.pmd.ant.PMDTask',
classpath: project.configurations.pmd.asPath)
ant.pmd(failOnRuleViolation: false,
failuresPropertyName: "pmdFailureCount",
minimumPriority: extension.rulesMinimumPriority.get()) {
sourceSets.main.allJava.srcDirs.each {
fileset(dir: it)
}
extension.ruleSets.each {
ruleset(it)
}
extension.ruleSetFiles.each {
ruleset(it)
}
if (extension.ruleSetConfig != null) {
ruleset(extension.ruleSetConfig.asFile())
}
Provider<RegularFile> reportsDir = project.getLayout()
.file(project.getProviders().provider({a -> extension.getReportsDir()}) as Provider<File>)
formatter(type: 'sarif', toFile: new File(reportsDir.get().getAsFile(), 'main.sarif'))
formatter(type: 'html', toFile: new File(reportsDir.get().getAsFile(), 'main.html'))
if (extension.consoleOutput) {
formatter(type: 'textcolor', toConsole: true)
}
}
def failureCount = ant.project.properties["pmdFailureCount"]
if (failureCount) {
def message = "$failureCount PMD rule violations were found."
if (extension.ignoreFailures || ((failureCount as Integer) <= extension.maxFailures.get())) {
logger.warn(message)
} else {
throw new GradleException(message)
}
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task('generateJava', type: Copy) {
def templateContext = [version: project.version]
inputs.properties templateContext // Register context as input so that task doesn't skip when props are updated
from 'src/template/java'
into "${buildDir}/generated/java"
expand templateContext
}
project.compileJava {
dependsOn generateJava
sourceCompatibility '11'
targetCompatibility '11'
}
project.compileTestJava {
sourceCompatibility '11'
targetCompatibility '11'
}
project.compileIntegrationTestJava {
sourceCompatibility '11'
targetCompatibility '11'
}
java {
withJavadocJar()
withSourcesJar()
}
// Generate manifest.json file to be compliant with Confluent Hub client
tasks.register('generateConfluentConnectManifest', Copy) {
def templateContext = [
"project": project.properties
]
from 'src/template/manifest'
into "${buildDir}/generated/manifest"
expand templateContext
}
distributions {
main {
contents {
from('etc/solace_source.properties') { into 'etc' }
from('etc/solace_source_properties.json') { into 'etc' }
from('doc/distribution-readme.md') { into 'doc' }
from('LICENSE') { into 'doc' }
from('THIRD-PARTY-LICENSES') { into 'doc' }
from(generateConfluentConnectManifest) {into ''}
into('lib') {
from jar
from(project.configurations.runtimeClasspath)
}
// from jar
}
}
}
publishing {
publications {
maven(MavenPublication) {
from components.java
pom {
name = "Solace PubSub+ Connector for Kafka: Source"
description = "The PubSub+ Kafka Source Connector consumes PubSub+ event broker real-time queue or topic data events and streams them to a Kafka topic as Source Records."
url = "https://github.com/SolaceProducts/pubsubplus-connector-kafka-source"
packaging = "jar"
licenses {
license {
name = "Apache License, Version 2.0"
url = "https://github.com/SolaceProducts/pubsubplus-connector-kafka-source/blob/master/LICENSE"
distribution = "repo"
}
}
organization {
name = "Solace"
url = "https://www.solace.com"
}
developers {
developer {
name = "Support for Solace"
email = "[email protected]"
organization = "Solace"
organizationUrl = "https://solace.community"
}
}
scm {
connection = "scm:git:git://github.com/SolaceProducts/pubsubplus-connector-kafka-source.git"
developerConnection = "scm:git:[email protected]:SolaceProducts/pubsubplus-connector-kafka-source.git"
url = "https://github.com/SolaceProducts/pubsubplus-connector-kafka-source.git"
}
}
}
}
repositories {
maven {
def releasesUrl = uri('http://apps-jenkins:9090/nexus/content/repositories/releases')
def snapshotRepositoryUrl = uri('http://apps-jenkins:9090/nexus/content/repositories/snapshots')
url = isSnapshot ? snapshotRepositoryUrl : releasesUrl
allowInsecureProtocol = true
name = 'internal'
credentials {
username = project.properties[name + "Username"]
password = project.properties[name + "Password"]
}
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri('https://oss.sonatype.org/service/local/')
snapshotRepositoryUrl = uri('https://oss.sonatype.org/content/repositories/snapshots')
// gets credentials from project.properties["sonatypeUsername"] project.properties["sonatypePassword"]
}
}
}
signing {
required {
!isSnapshot
}
useGpgCmd()
sign publishing.publications.maven
}
tasks.withType(Sign) {
onlyIf {
gradle.taskGraph.allTasks.any {task ->
task.name.startsWith("publish") && task.name.contains('Sonatype')
}
}
shouldRunAfter test, integrationTest
}
tasks.withType(InitializeNexusStagingRepository).configureEach {
dependsOn test, integrationTest
shouldRunAfter tasks.withType(Sign)
}
tasks.withType(PublishToMavenRepository).configureEach {
dependsOn test, integrationTest
}