/
build.gradle.kts
308 lines (258 loc) · 8.61 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
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
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileInputStream
import java.net.URL
import java.util.Properties
plugins {
jacoco
java
kotlin("jvm") version "1.3.61"
`maven-publish`
id("com.github.ben-manes.versions") version "0.27.0"
id("com.jfrog.bintray") version "1.8.4"
id("io.gitlab.arturbosch.detekt") version "1.5.1"
id("net.thauvin.erik.gradle.semver") version "1.0.4"
id("org.jetbrains.dokka") version "0.10.1"
id("org.jetbrains.kotlin.kapt").version("1.3.61")
id("org.jetbrains.kotlin.plugin.serialization").version("1.3.61")
id("org.jmailen.kotlinter") version "2.3.0"
id("org.sonarqube") version "2.8"
}
group = "net.thauvin.erik"
description = "Akismet for Kotlin/Java, a client library for accessing the Automattic Kismet (Akismet) spam comments filtering service."
val gitHub = "ethauvin/$name"
val mavenUrl = "https://github.com/$gitHub"
val deployDir = "deploy"
var isRelease = "release" in gradle.startParameter.taskNames
var semverProcessor = "net.thauvin.erik:semver:1.2.0"
val publicationName = "mavenJava"
object VersionInfo {
const val okhttp = "4.3.1"
}
val versions: VersionInfo by extra { VersionInfo }
// Load local.properties
File("local.properties").apply {
if (exists()) {
FileInputStream(this).use { fis ->
Properties().apply {
load(fis)
forEach { (k, v) ->
extra[k as String] = v
}
}
}
}
}
repositories {
jcenter()
}
dependencies {
kapt(semverProcessor)
compileOnly(semverProcessor)
compile("javax.servlet:javax.servlet-api:4.0.1")
compile("com.squareup.okhttp3:okhttp:${versions.okhttp}")
compile("com.squareup.okhttp3:logging-interceptor:${versions.okhttp}")
compile(kotlin("stdlib"))
compile("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.13.0")
testImplementation("org.mockito:mockito-core:3.2.4")
testImplementation("org.testng:testng:7.1.1")
}
kapt {
arguments {
arg("semver.project.dir", projectDir)
}
}
detekt {
//input = files("src/main/kotlin", "src/test/kotlin")
//filters = ".*/resources/.*,.*/build/.*"
baseline = project.rootDir.resolve("detekt-baseline.xml")
}
kotlinter {
ignoreFailures = false
reporters = arrayOf("html")
experimentalRules = false
disabledRules = arrayOf("import-ordering")
}
jacoco {
toolVersion = "0.8.3"
}
sonarqube {
properties {
property("sonar.projectKey", "ethauvin_$name")
property("sonar.sourceEncoding", "UTF-8")
}
}
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.getByName("main").allSource)
}
val javadocJar by tasks.creating(Jar::class) {
dependsOn(tasks.dokka)
from(tasks.dokka)
archiveClassifier.set("javadoc")
description = "Assembles a JAR of the generated Javadoc."
group = JavaBasePlugin.DOCUMENTATION_GROUP
}
val dokkaDocs by tasks.creating(DokkaTask::class) {
outputFormat = "gfm"
outputDirectory = "$projectDir"
configuration {
moduleName = "docs"
sourceLink {
path = file("$projectDir/src/main/kotlin").toURI().toString().replace("file:", "")
url = "https://github.com/ethauvin/${project.name}/tree/master/src/main/kotlin"
lineSuffix = "#L"
}
jdkVersion = 8
externalDocumentationLink {
url = URL("https://javaee.github.io/javaee-spec/javadocs/")
packageListUrl = URL("https://javaee.github.io/javaee-spec/javadocs/package-list")
}
includes = listOf("config/dokka/packages.md")
includeNonPublic = false
}
}
tasks {
withType<Test> {
useTestNG()
}
withType<JacocoReport> {
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
withType<GenerateMavenPom> {
destination = file("$projectDir/pom.xml")
}
assemble {
dependsOn(sourcesJar, javadocJar)
}
clean {
doLast {
project.delete(fileTree(deployDir))
}
}
dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
configuration {
sourceLink {
path = "src/main/kotlin"
url = "https://github.com/ethauvin/${project.name}/tree/master/src/main/kotlin"
lineSuffix = "#L"
}
jdkVersion = 8
externalDocumentationLink {
url = URL("https://javaee.github.io/javaee-spec/javadocs/")
packageListUrl = URL("https://javaee.github.io/javaee-spec/javadocs/package-list")
}
includes = listOf("config/dokka/packages.md")
includeNonPublic = false
}
}
val copyToDeploy by registering(Copy::class) {
from(configurations.runtime) {
exclude("annotations-*.jar")
}
from(jar)
into(deployDir)
}
register("deploy") {
description = "Copies all needed files to the $deployDir directory."
group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn("build", "jar")
outputs.dir(deployDir)
inputs.files(copyToDeploy)
mustRunAfter("clean")
}
val gitIsDirty by registering(Exec::class) {
description = "Fails if git has uncommitted changes."
group = "verification"
commandLine("git", "diff", "--quiet", "--exit-code")
}
val gitTag by registering(Exec::class) {
description = "Tags the local repository with version ${project.version}"
group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn(gitIsDirty)
if (isRelease) {
commandLine("git", "tag", "-a", project.version, "-m", "Version ${project.version}")
}
}
val bintrayUpload by existing(BintrayUploadTask::class) {
dependsOn(publishToMavenLocal, gitTag)
}
register("release") {
description = "Publishes version ${project.version} to Bintray."
group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn("wrapper", bintrayUpload)
}
"sonarqube" {
dependsOn("jacocoTestReport")
}
}
fun findProperty(s: String) = project.findProperty(s) as String?
bintray {
user = findProperty("bintray.user")
key = findProperty("bintray.apikey")
publish = isRelease
setPublications(publicationName)
pkg.apply {
repo = "maven"
name = project.name
desc = description
websiteUrl = mavenUrl
issueTrackerUrl = "$mavenUrl/issues"
githubRepo = gitHub
githubReleaseNotesFile = "README.md"
vcsUrl = "$mavenUrl.git"
setLabels("kotlin", "java", "akismet", "comments", "spam", "blog", "automattic", "kismet")
publicDownloadNumbers = true
version.apply {
name = project.version as String
desc = description
vcsTag = project.version as String
gpg.apply {
sign = true
}
}
}
}
publishing {
publications {
create<MavenPublication>(publicationName) {
from(components["java"])
artifact(sourcesJar)
artifact(javadocJar)
pom.withXml {
asNode().apply {
appendNode("name", project.name)
appendNode("description", project.description)
appendNode("url", mavenUrl)
appendNode("licenses").appendNode("license").apply {
appendNode("name", "BSD 3-Clause")
appendNode("url", "https://opensource.org/licenses/BSD-3-Clause")
}
appendNode("developers").appendNode("developer").apply {
appendNode("id", "ethauvin")
appendNode("name", "Erik C. Thauvin")
appendNode("email", "erik@thauvin.net")
}
appendNode("scm").apply {
appendNode("connection", "scm:git:$mavenUrl.git")
appendNode("developerConnection", "scm:git:git@github.com:$gitHub.git")
appendNode("url", mavenUrl)
}
appendNode("issueManagement").apply {
appendNode("system", "GitHub")
appendNode("url", "$mavenUrl/issues")
}
}
}
}
}
}