-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
164 lines (142 loc) · 4.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
import org.jetbrains.dokka.gradle.DokkaTask
plugins {
kotlin("jvm") version "1.9.23"
id("org.jetbrains.dokka") version "1.9.20"
id("com.palantir.git-version") version "3.0.0"
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
idea
}
group = "de.joshuagleitze"
version = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag.drop("v")
status = if (isSnapshot) "snapshot" else "release"
val gitRef = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag
subprojects {
group = rootProject.group
version = rootProject.version
status = rootProject.status
}
allprojects {
plugins.apply("org.gradle.idea")
repositories {
mavenCentral()
}
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
}
tasks.withType<Test> {
reports.junitXml.required.set(true)
}
val ossrhUsername: String? by project
val ossrhPassword: String? by project
val githubRepository: String? by project
val githubOwner = githubRepository?.split("/")?.get(0)
val githubToken: String? by project
val mavenCentral = nexusPublishing.repositories.sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
}
subprojects {
afterEvaluate {
apply {
plugin("org.jetbrains.dokka")
plugin("org.gradle.maven-publish")
plugin("org.gradle.signing")
}
val sourcesJar by tasks.registering(Jar::class) {
group = "build"
description = "Assembles the source code into a jar"
archiveClassifier.set("sources")
from(sourceSets.main.map { it.allSource })
}
tasks.withType<DokkaTask> {
dokkaSourceSets.named("main") {
this.DokkaSourceSetID(if (extra.has("artifactId")) extra["artifactId"] as String else project.name)
sourceLink {
val projectPath = projectDir.absoluteFile.relativeTo(rootProject.projectDir.absoluteFile)
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(uri("https://github.com/$githubRepository/blob/$gitRef/$projectPath/src/main/kotlin").toURL())
remoteLineSuffix.set("#L")
}
}
}
val dokkaJar by tasks.registering(Jar::class) {
group = "build"
description = "Assembles the Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.named("dokkaJavadoc"))
}
artifacts {
archives(sourcesJar)
archives(dokkaJar)
}
signing {
val signingKey: String? by project
val signingKeyPassword: String? by project
useInMemoryPgpKeys(signingKey, signingKeyPassword)
}
publishing.publications.create<MavenPublication>("maven") {
artifactId = if (extra.has("artifactId")) extra["artifactId"] as String else project.name
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
signing.sign(this)
pom {
name.set("$groupId:$artifactId")
if (extra.has("description")) description.set(extra["description"] as String)
inceptionYear.set("2020")
url.set("https://github.com/$githubRepository")
ciManagement {
system.set("GitHub Actions")
url.set("https://github.com/$githubRepository/actions")
}
issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/$githubRepository/issues")
}
developers {
developer {
name.set("Joshua Gleitze")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:https://github.com/$githubRepository.git")
developerConnection.set("scm:git:git://[email protected]:$githubRepository.git")
url.set("https://github.com/$githubRepository")
}
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
distribution.set("repo")
}
}
}
}
val githubPackages = publishing.repositories.maven("https://maven.pkg.github.com/$githubRepository") {
name = "GitHubPackages"
credentials {
username = githubOwner
password = githubToken
}
}
val publishToGithub = tasks.named("publishAllPublicationsTo${githubPackages.name.firstUpper()}Repository")
val publishToMavenCentral = tasks.named("publishTo${mavenCentral.name.firstUpper()}")
tasks.register("release") {
group = "release"
description = "Releases the project to all remote repositories"
dependsOn(publishToGithub, publishToMavenCentral, rootProject.tasks.closeAndReleaseStagingRepository)
}
rootProject.tasks.closeAndReleaseStagingRepository { mustRunAfter(publishToMavenCentral) }
}
}
val Project.isSnapshot get() = versionDetails.commitDistance != 0
fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this
fun String.firstUpper() = this.replaceFirstChar { it.titlecase() }
val Project.versionDetails get() = (this.extra["versionDetails"] as groovy.lang.Closure<*>)() as com.palantir.gradle.gitversion.VersionDetails