-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle.kts
235 lines (202 loc) · 6.9 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
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories {
google()
mavenCentral()
jcenter {
content {
includeGroup("org.jetbrains.kotlinx")
}
}
}
val ktlintVersion = "0.40.0"
configurations.classpath {
resolutionStrategy {
force(
"com.pinterest.ktlint:ktlint-core:$ktlintVersion",
"com.pinterest.ktlint:ktlint-reporter-checkstyle:$ktlintVersion",
"com.pinterest.ktlint:ktlint-reporter-json:$ktlintVersion",
"com.pinterest.ktlint:ktlint-reporter-html:$ktlintVersion",
"com.pinterest.ktlint:ktlint-reporter-plain:$ktlintVersion",
"com.pinterest.ktlint:ktlint-ruleset-experimental:$ktlintVersion",
"com.pinterest.ktlint:ktlint-ruleset-standard:$ktlintVersion"
)
}
}
}
plugins {
kotlin("jvm") version "1.4.32"
id("org.jetbrains.dokka") version "1.4.30"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.4.0"
id("jacoco")
`maven-publish`
signing
id("com.github.nbaztec.coveralls-jacoco") version "1.2.5"
id("org.jmailen.kotlinter") version "3.3.0"
id("io.gitlab.arturbosch.detekt") version "1.16.0"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
group = "dev.stalla"
val tagName = System.getenv("GITHUB_REF")?.let { ref ->
if (ref.startsWith("refs/tags/")) {
ref.substringAfterLast('/')
} else {
null
}
}
version = tagName ?: "1.0.0-SNAPSHOT"
val junit5Version = "5.7.2"
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junit5Version")
testImplementation("com.willowtreeapps.assertk:assertk:0.24")
testImplementation("org.xmlunit:xmlunit-core:2.8.2")
testImplementation("org.reflections:reflections:0.10.2")
}
kotlin {
explicitApi()
}
detekt {
input = files("src/main/java", "src/main/kotlin")
config = files("config/detekt/config.yml")
buildUponDefaultConfig = true
reports {
sarif {
enabled = true
}
}
}
apiValidation {
nonPublicMarkers.add("dev.stalla.util.InternalAPI")
}
val javadocJar by tasks.creating(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.dokkaJavadoc.get().outputs)
}
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(kotlin.sourceSets.main.get().kotlin.srcDirs)
}
fun searchPropertyOrNull(name: String, vararg aliases: String): String? {
fun searchEverywhere(name: String): String? =
findProperty(name) as? String? ?: System.getenv(name)
searchEverywhere(name)?.let { return it }
aliases.forEach { alias ->
searchEverywhere(alias)?.let { return it }
}
return null
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(searchPropertyOrNull("SONATYPE_USERNAME", "sonatypeUsername"))
password.set(searchPropertyOrNull("SONATYPE_PASSWORD", "sonatypePassword"))
}
}
}
signing {
val secretKey: String? = rootProject.file("secring.txt")
.takeIf { it.exists() }
?.readText()
val password: String? = searchPropertyOrNull("SIGNING_PASSWORD", "signingPassword")
useInMemoryPgpKeys(secretKey, password)
}
publishing {
publications.create<MavenPublication>(project.name) {
artifact(javadocJar)
artifact(sourcesJar)
from(components["kotlin"])
pom {
name.set(project.name)
description.set("RSS reading and writing library for podcasts, written in Kotlin and Java-friendly")
url.set("https://github.com/mpgirro/stalla")
scm {
url.set("https://github.com/mpgirro/stalla.git")
}
licenses {
license {
name.set("BSD 3-Clause License")
url.set("https://github.com/mpgirro/stalla/blob/master/LICENSE")
}
}
developers {
developer {
id.set("mpgirro")
name.set("Maximilian Irro")
url.set("https://github.com/mpgirro")
}
developer {
id.set("rock3r")
name.set("Sebastiano Poggi")
url.set("https://github.com/rock3r")
}
}
}
signing.sign(this)
}
}
tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.contracts.ExperimentalContracts",
"-Xopt-in=dev.stalla.util.InternalAPI",
"-Xopt-in=dev.stalla.util.ExperimentalAPI"
)
}
}
withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
withType<JacocoReport> {
reports {
html.isEnabled = true
xml.isEnabled = true
}
}
withType<Detekt> {
// Required for type resolution
jvmTarget = "1.8"
}
afterEvaluate {
// Needs to happen lazily as :detektMain is added late
named("check") {
dependsOn(named<Detekt>("detektMain"))
}
}
val checkVersionBeforeRegistering by registering {
group = "publishing"
description = "Checks that the version is not set to a SNAPSHOT value before releasing to Maven Central"
doFirst {
logger.warn("Project version: ${project.version}")
logger.warn("GITHUB_REF: ${System.getenv("GITHUB_REF")}")
if (project.version.toString().endsWith("-SNAPSHOT")) {
throw GradleException("Cannot publish a snapshot release to Maven Central")
}
}
}
register("publishToMavenCentral") {
group = "publishing"
description = "Publishes the the current revision to Maven Central, with pre-flight sanity checks"
doLast {
logger.warn("Successfully published ${project.group}:${project.name}:${project.version} to Maven Central")
}
dependsOn(checkVersionBeforeRegistering, named("publishToSonatype"), named("closeAndReleaseSonatypeStagingRepository"))
}
}