Configure publishing for mirai-bom

This commit is contained in:
Him188 2021-12-06 14:31:25 +00:00
parent 561d333cc7
commit 61ce69c328
2 changed files with 18 additions and 7 deletions

View File

@ -20,7 +20,6 @@ import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.registering
fun Project.configureRemoteRepos() { fun Project.configureRemoteRepos() {
tasks.register("ensureMavenCentralAvailable") { tasks.register("ensureMavenCentralAvailable") {
@ -73,16 +72,17 @@ fun Project.configureRemoteRepos() {
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun Project.configurePublishing( inline fun Project.configurePublishing(
artifactId: String, artifactId: String,
vcs: String = "https://github.com/mamoe/mirai" vcs: String = "https://github.com/mamoe/mirai",
addProjectComponents: Boolean = true
) { ) {
configureRemoteRepos() configureRemoteRepos()
apply<ShadowPlugin>() apply<ShadowPlugin>()
val sourcesJar by tasks.registering(Jar::class) { val sourcesJar = if (!addProjectComponents) null else tasks.maybeCreate("sourcesJar", Jar::class.java).apply {
archiveClassifier.set("sources") archiveClassifier.set("sources")
from(sourceSets["main"].allSource) from(sourceSets["main"].allSource)
} }
val stubJavadoc = tasks.register("javadocJar", Jar::class) { val stubJavadoc = if (!addProjectComponents) null else tasks.register("javadocJar", Jar::class) {
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
archiveClassifier.set("javadoc") archiveClassifier.set("javadoc")
} }
@ -90,7 +90,7 @@ inline fun Project.configurePublishing(
publishing { publishing {
publications { publications {
register("mavenJava", MavenPublication::class) { register("mavenJava", MavenPublication::class) {
from(components["java"]) if (addProjectComponents) from(components["java"])
groupId = rootProject.group.toString() groupId = rootProject.group.toString()
setArtifactId(artifactId) setArtifactId(artifactId)
@ -101,8 +101,8 @@ inline fun Project.configurePublishing(
vcs = vcs vcs = vcs
) )
artifact(sourcesJar.get()) sourcesJar?.let { artifact(it) }
artifact(stubJavadoc.get()) stubJavadoc?.get()?.let { artifact(it) }
} }
} }
configGpgSign(this@configurePublishing) configGpgSign(this@configurePublishing)

View File

@ -1,3 +1,12 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
plugins { plugins {
`java-platform` `java-platform`
`maven-publish` `maven-publish`
@ -36,3 +45,5 @@ publishing {
} }
} }
} }
configurePublishing("mirai-bom", addProjectComponents = false)