-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
213 lines (187 loc) · 6.21 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
import de.marcphilipp.gradle.nexus.NexusRepository
import org.gradle.api.JavaVersion.VERSION_1_8
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.24"
id("com.palantir.git-version") version "3.1.0"
id("org.jetbrains.dokka") version "1.9.20"
id("de.marcphilipp.nexus-publish") version "0.4.0"
id("io.codearte.nexus-staging") version "0.30.0"
`maven-publish`
signing
}
allprojects {
repositories {
mavenCentral()
}
}
group = "de.joshuagleitze"
val gitRef = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag
version = if (isSnapshot) gitRef else gitRef.drop("v")
status = if (isSnapshot) "snapshot" else "release"
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
nexusStaging {
username = ossrhUsername
password = ossrhPassword
numberOfRetries = 42
}
subprojects {
group = rootProject.group
version = rootProject.version
status = rootProject.status
afterEvaluate {
if (plugins.hasPlugin("org.jetbrains.kotlin.jvm")) {
tasks.test {
useJUnitPlatform()
reports.junitXml.isEnabled = true
}
java {
sourceCompatibility = VERSION_1_8
targetCompatibility = VERSION_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
// TODO workaround for https://youtrack.jetbrains.com/issue/KT-41142
freeCompilerArgs += "-Xno-optimized-callable-references"
}
}
}
if (willBePublished) {
apply {
plugin("org.jetbrains.dokka")
plugin("de.marcphilipp.nexus-publish")
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.get().allSource)
}
tasks.withType<DokkaTask> {
dokkaSourceSets.named("main") {
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")
}
externalDocumentationLink("https://docs.gradle.org/current/javadoc/")
val atriumVersion: String by project
externalDocumentationLink("https://docs.atriumlib.org/$atriumVersion/doc/")
}
}
val dokkaJar by tasks.registering(Jar::class) {
group = "build"
description = "Assembles the Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokkaJavadoc)
}
artifacts {
archives(sourcesJar)
archives(dokkaJar)
}
lateinit var publication: MavenPublication
lateinit var githubPackages: ArtifactRepository
lateinit var mavenCentral: NexusRepository
publishing {
publications {
publication = create<MavenPublication>("maven") {
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
pom {
name.set(provider { "$groupId:$artifactId" })
description.set("Atrium assertions for testing Gradle plugins.")
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("dev@joshuagleitze.de")
}
}
scm {
connection.set("scm:git:https://github.com/$githubRepository.git")
developerConnection.set("scm:git:git://git@github.com:$githubRepository.git")
url.set("https://github.com/$githubRepository")
}
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
distribution.set("repo")
}
}
}
}
}
repositories {
githubPackages = maven("https://maven.pkg.github.com/$githubRepository") {
name = "GitHubPackages"
credentials {
username = githubOwner
password = githubToken
}
}
}
}
nexusPublishing {
repositories {
mavenCentral = sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
}
}
}
val publishToGithub = tasks.named("publishAllPublicationsTo${githubPackages.name.capitalize()}Repository")
val publishToMavenCentral = tasks.named("publishTo${mavenCentral.name.capitalize()}")
signing {
val signingKey: String? by project
val signingKeyPassword: String? by project
useInMemoryPgpKeys(signingKey, signingKeyPassword)
sign(publication)
}
val checkDependenciesBeforePublishing by tasks.registering {
group = "publishing"
description = "Checks that all dependencies are also being published"
doFirst {
project.configurations.runtimeClasspath {
allDependencies.withType<ProjectDependency> {
check(dependencyProject.willBePublished) {
"This project has a dependency on $dependencyProject, but the latter will not be published!"
}
}
}
}
}
rootProject.tasks.closeAndReleaseRepository { mustRunAfter(publishToMavenCentral) }
publishToMavenCentral { dependsOn(checkDependenciesBeforePublishing) }
publishToGithub { dependsOn(checkDependenciesBeforePublishing) }
task("release") {
group = "release"
description = "Releases the project to all remote repositories"
dependsOn(publishToGithub, publishToMavenCentral, rootProject.tasks.closeAndReleaseRepository)
}
}
}
}
val Project.isSnapshot get() = versionDetails.commitDistance != 0
fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this
val Project.versionDetails get() = (this.extra["versionDetails"] as groovy.lang.Closure<*>)() as com.palantir.gradle.gitversion.VersionDetails
val Project.willBePublished get() = this.extra.properties["willBePublished"] as Boolean? ?: false