-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
228 lines (199 loc) · 7.24 KB
/
build.gradle.kts
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
/*
*
* Copyright 2012-2021 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
import net.researchgate.release.ReleaseExtension
import java.net.URI
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
}
plugins {
`lifecycle-base`
jacoco
`maven-publish`
signing
java
id("io.snyk.gradle.plugin.snykplugin")
}
allprojects {
// Configures the Jacoco tool version to be the same for all projects that have it applied.
pluginManager.withPlugin("jacoco") {
// If this project has the plugin applied, configure the tool version.
jacoco {
toolVersion = "0.8.10"
}
}
apply {
plugin(JavaPlugin::class.java)
plugin("java-library")
plugin("jacoco")
plugin("maven-publish")
plugin("net.researchgate.release")
plugin("io.snyk.gradle.plugin.snykplugin")
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// TODO: Investigate. Snyk fails on older version of this dependency.
"dataFiles"("org.json:json:20231013")
}
group = "com.aerospike"
// Common dependency versions.
extra["aerospikeClientVersion"] = "7.2.0"
extra["jacksonVersion"] = "2.15.3"
dependencies {
// Lombok for its @Generated annotation that jacoco ignores
val lombokVersion = "1.18.30"
"compileOnly"("org.projectlombok:lombok:$lombokVersion")
"annotationProcessor"("org.projectlombok:lombok:$lombokVersion")
// JSR 305 for annotations
"compileOnly"("com.google.code.findbugs:jsr305:3.0.2")
// Aerospike Java Client
"compileOnly"("com.aerospike:aerospike-client:${project.extra["aerospikeClientVersion"]}")
// Jackson annotation
"compileOnly"("com.fasterxml.jackson.core:jackson-annotations:${project.extra["jacksonVersion"]}")
}
val compileJava: JavaCompile by tasks
compileJava.sourceCompatibility = "1.8"
compileJava.targetCompatibility = "1.8"
compileJava.options.apply {
compilerArgs.add("-Xlint:all")
compilerArgs.add("-Werror")
compilerArgs.add("-Xlint:-processing")
}
project.extensions.configure(ReleaseExtension::class) {
tagTemplate = "\$version"
}
tasks.getByName("afterReleaseBuild").dependsOn("publish")
publishing {
repositories {
maven {
val releaseRepo = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotRepo = URI("https://oss.sonatype.org/content/repositories/snapshots/")
url = if (!isSnapshotVersion(project.version)) releaseRepo else snapshotRepo
credentials {
username = project.properties["ossrhUsername"] as String
password = project.properties["ossrhPassword"] as String
}
}
}
publications {
create<MavenPublication>("mavenJava") {
artifactId = project.name
from(components["java"])
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
name.set("Aerospike Connect Inbound SDK")
description.set("Inbound SDK for message transformer or other plugins.")
url.set("https://github.com/aerospike/aerospike-connect-inbound-sdk")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
connection.set("scm:[email protected]:aerospike/aerospike-connect-inbound-sdk.git")
developerConnection.set("scm:[email protected]:aerospike/aerospike-connect-inbound-sdk.git")
url.set("https://github.com/aerospike/aerospike-connect-inbound-sdk")
}
developers {
developer {
name.set("Aerospike")
email.set("[email protected]")
organization.set("Aerospike")
url.set("https://www.aerospike.com/")
}
}
}
}
}
tasks.withType<PublishToMavenRepository>().configureEach {
onlyIf {
// Upload if snap shot version.
// If a proper release version upload only when release task is
// present. This prevents re-releasing re builds of released
// version.
isSnapshotVersion(project.version) || hasReleaseTask()
}
}
}
signing {
sign(publishing.publications.getByName("mavenJava"))
}
java {
withJavadocJar()
withSourcesJar()
}
tasks.javadoc {
options {
this as StandardJavadocDocletOptions
// Fail on Javadoc lint errors.
addBooleanOption("Xdoclint:all", true)
// This is a hack as we are not using Java15+.
// See https://stackoverflow.com/a/49544352/5611068.
addStringOption("Xwerror", "-quiet")
}
}
val snykTokens: String by project
val snykToken = snykTokens.split(",").map { it.trim() }.random()
tasks.create<Exec>("setup-snyk") {
commandLine("${project.rootDir}/snyk", "auth", snykToken)
}
tasks.getByName("snyk-check-binary").finalizedBy("setup-snyk")
/**
* Vulnerability scanning with Snyk.
*/
configure<io.snyk.gradle.plugin.SnykExtension> {
setApi(snykToken)
setSeverity("high")
setAutoDownload(true)
setArguments("--sub-project=" + project.name)
}
}
/**
* Check if current project version is a snapshot version.
*/
fun isSnapshotVersion(version: Any): Boolean {
return version.toString().endsWith("-SNAPSHOT")
}
/**
* Check if we are running a release task.
*/
fun hasReleaseTask(): Boolean {
val releaseTaskName = "afterReleaseBuild"
var hasRelease = false
gradle.taskGraph.allTasks.forEach {
if (it.name == releaseTaskName) {
hasRelease = true
return@forEach
}
}
return hasRelease
}