-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
174 lines (150 loc) · 4.71 KB
/
build.gradle.kts
File metadata and controls
174 lines (150 loc) · 4.71 KB
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
import org.gradle.kotlin.dsl.*
import kotlin.io.path.*
import org.jreleaser.model.Active.ALWAYS
plugins {
kotlin("jvm") version "2.3.21"
id("org.jetbrains.dokka-javadoc") version "2.2.0"
id("org.jetbrains.dokka") version "2.2.0"
`maven-publish`
signing
id("org.jreleaser") version "1.23.0"
}
group = "de.joshuagleitze"
version = if (version == "unspecified") "local" else version.toString().drop("v")
status = if (version == "local") "snapshot" else "release"
repositories {
mavenCentral()
}
dependencies {
testImplementation("ch.tutteli.atrium:atrium-fluent:1.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:6.0.3")
testImplementation("org.junit.jupiter:junit-jupiter-params:6.0.3")
constraints {
testImplementation(kotlin("reflect", KotlinVersion.CURRENT.toString()))
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.0.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:6.0.3")
}
val compilationTargetJavaVersion = JavaLanguageVersion.of(17)
java {
toolchain {
languageVersion = compilationTargetJavaVersion
}
}
val testTargetJavaVersion = providers
.gradleProperty("testTargetJavaVersion")
.map(JavaLanguageVersion::of)
.orElse(compilationTargetJavaVersion)
tasks.withType<Test>().configureEach {
useJUnitPlatform()
reports.junitXml.required = true
javaLauncher = javaToolchains.launcherFor {
languageVersion = testTargetJavaVersion
}
}
val githubRepository: String? by project
val githubOwner = githubRepository?.split("/")?.get(0)
val githubToken: String? by project
val sourcesJar by tasks.registering(Jar::class) {
group = "build"
description = "Assembles the source code into a jar"
archiveClassifier = "sources"
from(sourceSets.main.map { it.allSource })
}
dokka {
dokkaSourceSets.main {
sourceLink {
localDirectory = file("src/main/kotlin")
remoteUrl = uri("https://github.com/$githubRepository/blob/main/src/main/kotlin")
remoteLineSuffix = "#L"
}
}
}
val dokkaJar by tasks.registering(Jar::class) {
group = "build"
description = "Assembles the Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.named("dokkaGeneratePublicationJavadoc"))
}
lateinit var publication: MavenPublication
lateinit var githubPackages: ArtifactRepository
lateinit var mavenCentralStaging: MavenArtifactRepository
publishing {
publications {
publication = create<MavenPublication>("maven") {
from(components["java"])
artifact(sourcesJar)
artifact(dokkaJar)
pom {
name = "$groupId:$artifactId"
description = "Convert between different string notations commonly found in programming"
inceptionYear = "2020"
url = "https://github.com/$githubRepository"
ciManagement {
system = "GitHub Actions"
url = "https://github.com/$githubRepository/actions"
}
issueManagement {
system = "GitHub Issues"
url = "https://github.com/$githubRepository/issues"
}
developers {
developer {
name = "Joshua Gleitze"
email = "dev@joshuagleitze.de"
}
}
scm {
connection = "scm:git:https://github.com/$githubRepository.git"
developerConnection = "scm:git:git://git@github.com:$githubRepository.git"
url = "https://github.com/$githubRepository"
}
licenses {
license {
name = "MIT"
url = "https://opensource.org/licenses/MIT"
distribution = "repo"
}
}
}
}
}
repositories {
mavenCentralStaging = maven(layout.buildDirectory.dir("publish/maven-central-staging")) {
name = "MavenCentralStaging"
}
githubPackages = maven("https://maven.pkg.github.com/$githubRepository") {
name = "GitHubPackages"
credentials {
username = githubOwner
password = githubToken
}
}
}
}
signing {
useInMemoryPgpKeys(
providers.gradleProperty("signingKey").orNull,
providers.gradleProperty("signingKeyPassword").orNull
)
sign(publication)
}
jreleaser {
deploy.maven.mavenCentral.register("mavenCentral") {
url = "https://central.sonatype.com/api/v1/publisher"
active = ALWAYS
stagingRepository(mavenCentralStaging.url.toPath().absolutePathString())
sign = false
}
}
val jreleaserDeploy by tasks
jreleaserDeploy.mustRunAfter(mavenCentralStaging.publishTask)
val release by tasks.registering {
group = "release"
description = "Releases the project to all repositories"
dependsOn(githubPackages.publishTask, mavenCentralStaging.publishTask, jreleaserDeploy)
}
fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this
val ArtifactRepository.publishTask get() = tasks["publishAllPublicationsTo${this.name}Repository"]
fun ProviderFactory.requiredGradleProperty(name: String): Provider<String> = gradleProperty(name)
.orElse(provider { throw InvalidUserDataException("required project property `$name` was not set!") })