-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle
155 lines (135 loc) · 4.27 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
plugins {
id "distribution"
id "java"
alias(libs.plugins.sq)
}
// Gradle 8+ supported
group = 'com.ibm.cloud'
version = new File(rootDir, 'VERSION').text.trim()
// If the version says "snapshot" anywhere assume it is not a release
ext.isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).endsWith("-SNAPSHOT")
ext.kafkaConnectorPropertyFileName = 'com.ibm.cloud.cloudant.kafka.client.properties'
repositories {
if (System.env.ARTIFACTORY_URL != null) {
maven {
url "${System.env.ARTIFACTORY_URL}/cloudant-sdks-maven-virtual"
credentials {
username System.env.ARTIFACTORY_CREDS_USR
password System.env.ARTIFACTORY_CREDS_PSW
}
}
} else {
mavenCentral()
}
}
configurations {
// Provide the compileOnly kafka dependencies to testImplementation
// (i.e. make them available for test compile and test runtime)
testImplementation.extendsFrom compileOnly
}
dependencies {
implementation(libs.cloudant)
compileOnly(libs.bundles.kafkaProvided)
testImplementation(libs.bundles.testDeps)
// for logging output when running tests
testRuntimeOnly(libs.slf4jSimple)
}
// Java versions
sourceCompatibility = 1.8
targetCompatibility = 1.8
// Always UTF-8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
// Enable PowerMock with JDK 17+
test { jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED" }
//
// Generate client.properties
//
//task for generating a client properties file
class ClientProperties extends DefaultTask {
@OutputFile
File clientPropsPath = new File(project.kafkaConnectorPropertyFileName)
//internal
private Properties p = new Properties()
def load() {
//if there is a generated file already load the values
if (clientPropsPath.exists()) {
p.load(new FileInputStream(clientPropsPath));
}
}
@TaskAction
def save() {
p.put("user.agent.name", project.name)
p.put("user.agent.version", project.version)
p.store(new FileOutputStream(clientPropsPath), "User agent information for this client")
}
String getPropertyValue(String key) {
return p.getProperty(key)
}
}
//generate a client props file, make the jar task depend on this
task generateClientPropertiesFile(type: ClientProperties) {
clientPropsPath = new File(buildDir, "tmp/${project.kafkaConnectorPropertyFileName}")
outputs.upToDateWhen {
if (clientPropsPath.exists()) {
it.load()
return project.name.equals(it.getPropertyValue("user.agent.name")) && project.version.equals(it.getPropertyValue("user.agent.version"))
} else {
return false
}
}
}
jar.dependsOn generateClientPropertiesFile
// modify the jar task to pull in required dependencies and add the client properties file
jar {
into "META-INF", {
from generateClientPropertiesFile.clientPropsPath
from 'LICENSE'
}
}
distributions {
main {
contents {
from 'README.md'
from 'LICENSE'
from('docs') {
into 'docs'
}
from jar
// Package the runtimeClasspath dependencies (uber jar)
from configurations.runtimeClasspath
}
}
}
// Produce only a zip
distTar.enabled = false
test {
// Exclude the performance tests
exclude 'com/ibm/cloud/cloudant/kafka/performance/**'
}
tasks.withType(Test) {
// Transfer all gradle System properties to the test JVM
systemProperties = System.getProperties()
// Make sure it is UTF-8 for tests
systemProperty "file.encoding", "UTF-8"
}
task signDistZip(group: 'Other', description: 'Signs the archive produced by the \'distZip\' task.') {
onlyIf {
System.env["CODE_SIGNING_PFX_FILE"] != null
}
doLast {
def zipName = distZip.archiveFile.get().asFile
ant.signjar(
jar: zipName,
tsaurl: 'http://timestamp.digicert.com',
storetype: 'PKCS11',
keystore: 'NONE',
storepass: null,
providerclass: 'sun.security.pkcs11.SunPKCS11',
providerarg: '/home/jenkins/garasignconfig.txt',
alias: 'PRD0002797key',
preservelastmodified: 'true'
)
}
}