Skip to content

Commit ecc4c73

Browse files
committed
build: Use utility function to configure published artifacts
1 parent acaec64 commit ecc4c73

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

BotCommands-core/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,5 @@ kotlin {
159159
)
160160
}
161161
}
162+
163+
configurePublishedArtifact(artifactId = "BotCommands-core")

BotCommands-spring/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ dependencies {
3131
testImplementation(libs.spring.boot.starter)
3232
testRuntimeOnly(libs.spring.boot.devtools)
3333
}
34+
35+
configurePublishedArtifact(artifactId = "BotCommands-spring")

build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,4 @@ dependencies {
2929
dokka(projects.botCommandsSpring)
3030
}
3131

32-
mavenPublishing {
33-
pom {
34-
packaging = "pom"
35-
}
36-
}
32+
configurePublishedArtifact(artifactId = "BotCommands", packaging = "pom")

buildSrc/src/main/kotlin/BotCommands-publish-conventions.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ mavenPublishing {
9797
}
9898

9999
pom {
100-
name = project.name
101100
description = "A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library."
102101
url = "https://github.com/freya022/BotCommands"
103102
inceptionYear = "2020"
@@ -126,3 +125,9 @@ mavenPublishing {
126125
}
127126
}
128127
}
128+
129+
afterEvaluate {
130+
check(isPublishedArtifactConfigured(project)) {
131+
"Project '${project.path}' did not call 'configurePublishedArtifact'"
132+
}
133+
}

buildSrc/src/main/kotlin/tasks.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import org.gradle.api.Project
2+
import org.gradle.kotlin.dsl.*
3+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
4+
import org.jetbrains.dokka.gradle.DokkaExtension
5+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
6+
7+
private val configuredPublishedArtifacts = hashSetOf<String>()
8+
9+
fun isPublishedArtifactConfigured(project: Project) = project.path in configuredPublishedArtifacts
10+
11+
/**
12+
* Sets the provided [artifactId] as the Kotlin module name, Dokka module name & path, and Maven artifact ID.
13+
*/
14+
fun Project.configurePublishedArtifact(artifactId: String, packaging: String? = null) {
15+
check(artifactId.startsWith("BotCommands")) {
16+
"Artifact ID must start with 'BotCommands'"
17+
}
18+
19+
configuredPublishedArtifacts += this.path
20+
21+
tasks.withType<KotlinCompile> {
22+
compilerOptions {
23+
// Match up with Dokka's module path, as the wiki reconstructs wiki links with the module name
24+
moduleName = artifactId
25+
}
26+
}
27+
28+
extensions.configure<DokkaExtension>("dokka") {
29+
// For display in the nav sidebar
30+
moduleName = artifactId
31+
// For URLs consistent with the Kotlin module name
32+
modulePath = artifactId
33+
}
34+
35+
extensions.configure<MavenPublishBaseExtension>("mavenPublishing") {
36+
coordinates(artifactId = artifactId)
37+
38+
pom {
39+
// Sonatype requires
40+
this.name = artifactId
41+
this.packaging = packaging
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)