-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
275 lines (221 loc) · 8.67 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
import java.net.URL
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
with(Plugins) {
id("org.ajoberstar.grgit") version GRGIT
kotlin("jvm") version KOTLIN apply false
id("org.jetbrains.dokka") version DOKKA
signing
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version NEXUS
}
}
allprojects {
with(Coordinates) {
project.group = group
project.version = version
}
repositories {
mavenLocal()
mavenCentral()
}
}
// Normalizing project version
val prettyProjectVersion = rootProject.version.toString().run {
Regex("(\\d+\\.\\d+\\.\\d+).*").matchEntire(this)
?.run { groupValues[1] }
?: throw Error(
"Version '$this' does not match version pattern, e.g. 1.0.0-QUALIFIER"
)
}
// The latest commit ID
val buildRevision: String = grgit.log()[0].id ?: "dev"
subprojects {
apply {
plugin("java-library")
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.dokka")
plugin("signing")
plugin("maven-publish")
}
val sourceSets = project.extensions.getByType<SourceSetContainer>()
dependencies {
val implementation by configurations
val testImplementation by configurations
with(Dependencies) {
kotlinModules.forEach {
implementation("org.jetbrains.kotlin", "kotlin-$it", KOTLIN)
}
testImplementation(platform("org.junit:junit-bom:$JUPITER"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
}
val actualJavaVersion = if (JAVA_VERSION <= 10) "1.$JAVA_VERSION" else "$JAVA_VERSION"
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.valueOf(
"VERSION_${actualJavaVersion.replace(".", "_")}"
)
targetCompatibility = sourceCompatibility
}
tasks {
withType<JavaCompile> {
sourceCompatibility = actualJavaVersion
targetCompatibility = actualJavaVersion
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = actualJavaVersion
}
withType<Test> {
useJUnitPlatform()
}
withType<Jar> {
archiveBaseName.set("${rootProject.name}.${project.name}")
val buildTimeAndDate = OffsetDateTime.now()
val buildDate = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate)
val buildTime = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate)
val javaVersion = System.getProperty("java.version")
val javaVendor = System.getProperty("java.vendor")
val javaVmVersion = System.getProperty("java.vm.version")
with(Coordinates) {
manifest.attributes(
"Name" to group.replace(".", "/") + "/" + project.name + "/",
"Created-By" to "$javaVersion ($javaVendor $javaVmVersion)",
"Build-Date" to buildDate,
"Build-Time" to buildTime,
"Build-Revision" to buildRevision,
"Specification-Title" to project.name,
"Specification-Version" to prettyProjectVersion,
"Specification-Vendor" to vendor,
"Implementation-Title" to "$name-${project.name}",
"Implementation-Version" to buildRevision,
"Implementation-Vendor" to vendor,
"Bundle-Name" to "$name-${project.name}",
// the README.md file always contains the module description on its 3rd line.
"Bundle-Description" to projectDir.resolve("README.md").readLines()[2],
"Bundle-DocURL" to gitUrl,
"Bundle-Vendor" to vendor,
"Bundle-SymbolicName" to "$group.${project.name}",
)
}
from("LICENSE")
}
// Source artifact, including everything the 'main' does but not compiled.
create("sourcesJar", Jar::class) {
group = "build"
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
from("LICENSE")
}
withType<DokkaTask>().configureEach {
moduleName.set("${Coordinates.name}-${project.name}")
}
withType<DokkaTaskPartial>().configureEach {
moduleName.set(project.name)
dokkaSourceSets.configureEach {
includes.from(projectDir.resolve("README.md"))
displayName.set("${Coordinates.name}/${moduleName.get()} on ${Coordinates.gitHost}")
skipDeprecated.set(false)
includeNonPublic.set(false)
skipEmptyPackages.set(true)
reportUndocumented.set(true)
suppressObviousFunctions.set(true)
// Link the source to the documentation
sourceLink {
localDirectory.set(file("src"))
remoteUrl.set(
URL(
"${Coordinates.gitUrl}/tree/${Coordinates.mainGitBranch}/${project.name}/src"
)
)
}
/**
* @see config.Dokka.externalDocumentations
*/
config.Dokka.externalDocumentations.forEach {
externalDocumentationLink { url.set(URL(it)) }
}
}
}
// The Javadoc artifact, containing the Dokka output and the LICENSE file.
create("javadocJar", Jar::class) {
group = "build"
archiveClassifier.set("javadoc")
val dokkaHtml by getting
dependsOn(dokkaHtml)
from(dokkaHtml)
from("LICENSE")
}
}
publishing.publications {
create("mavenJava", MavenPublication::class.java) {
from(components["java"])
groupId = project.group.toString()
version = project.version.toString()
with(Coordinates) {
pom {
name.set(this@with.name)
description.set(this@with.description)
url.set(gitUrl)
with(Pom) {
licenses {
licenses.forEach {
license {
name.set(it.name)
url.set(it.url)
distribution.set(it.distribution)
}
}
}
developers {
developers.forEach {
developer {
id.set(it.id)
name.set(it.name)
email.set(it.email)
}
}
}
}
scm {
connection.set("scm:git:git://$gitHost/$repoId.git")
developerConnection.set(
"scm:git:ssh://$gitHost/$repoId.git"
)
url.set(gitUrl)
}
}
}
signing {
isRequired = project.properties["signing.keyId"] != null
sign(this@create)
}
}
}
}
tasks.withType<DokkaMultiModuleTask>().configureEach {
val moduleFile = File(
temporaryDir,
"MODULE.${java.util.UUID.randomUUID()}.md"
).apply {
writeText("# ${Coordinates.name} by ${Coordinates.vendor}\n${Coordinates.description}\n<a href=\"${Coordinates.gitUrl}\">Source</a>")
}
moduleName.set(Coordinates.name)
includes.from(moduleFile)
}
// Configure publishing to Maven Central
nexusPublishing.repositories.sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(
uri(
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
)
)
// Skip this step if environment variables NEXUS_USERNAME or NEXUS_PASSWORD aren't set.
username.set(properties["NEXUS_USERNAME"] as? String ?: return@sonatype)
password.set(properties["NEXUS_PASSWORD"] as? String ?: return@sonatype)
}