aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main/kotlin/org/jetbrains
diff options
context:
space:
mode:
authorKamil Doległo <9080183+kamildoleglo@users.noreply.github.com>2021-06-23 12:33:19 +0200
committerGitHub <noreply@github.com>2021-06-23 12:33:19 +0200
commitc2182b766a65619c859c0fc871a8a6334d66f199 (patch)
tree41624b51bcdb79f7f48fc436878b35120d77197d /buildSrc/src/main/kotlin/org/jetbrains
parent522775119b1f31d5f478662402eb29a5de9e0f12 (diff)
downloaddokka-c2182b766a65619c859c0fc871a8a6334d66f199.tar.gz
dokka-c2182b766a65619c859c0fc871a8a6334d66f199.tar.bz2
dokka-c2182b766a65619c859c0fc871a8a6334d66f199.zip
Add maven central publication (#1688)
* Add OSSRH repositories * Rewrite Gradle plugin publication * Add publication version assertion * Use Nexus publish plugin for publishing to Sonatype * Remove explicit publishing from s3 tests * Don't document Dokka for local publication * Fix a bug with closing Sonatype repository * Bump internal Dokka version * Move publication version check to the validate task * Fix Gradle plugin publication * Bump Dokka and gradle plugin-publish versions * Do not run Dokka for test tasks * Do not fail all runs in a workflow * Reduce JVM memory limit
Diffstat (limited to 'buildSrc/src/main/kotlin/org/jetbrains')
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt28
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt3
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt5
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt16
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/publication.kt42
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/taskUtils.kt9
6 files changed, 87 insertions, 16 deletions
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
index 42af6e8e..c4f22a90 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
@@ -4,18 +4,36 @@ package org.jetbrains
import org.gradle.api.Project
-internal enum class DokkaPublicationChannel {
+enum class DokkaPublicationChannel {
SpaceDokkaDev,
BintrayKotlinDev,
BintrayKotlinEap,
- BintrayKotlinDokka;
+ BintrayKotlinDokka,
+ MavenCentral,
+ MavenCentralSnapshot;
val isSpaceRepository get() = this == SpaceDokkaDev
val isBintrayRepository
get() = when (this) {
- SpaceDokkaDev -> false
BintrayKotlinDev, BintrayKotlinEap, BintrayKotlinDokka -> true
+ else -> false
+ }
+
+ val isMavenRepository
+ get() = when (this) {
+ MavenCentral, MavenCentralSnapshot -> true
+ else -> false
+ }
+
+ val acceptedDokkaVersionTypes: List<DokkaVersionType>
+ get() = when(this) {
+ MavenCentral -> listOf(DokkaVersionType.Release)
+ MavenCentralSnapshot -> listOf(DokkaVersionType.Snapshot)
+ SpaceDokkaDev -> listOf(DokkaVersionType.Release, DokkaVersionType.Dev, DokkaVersionType.MC, DokkaVersionType.Snapshot)
+ BintrayKotlinDev -> listOf(DokkaVersionType.Dev, DokkaVersionType.MC, DokkaVersionType.Snapshot)
+ BintrayKotlinEap -> listOf(DokkaVersionType.MC)
+ BintrayKotlinDokka -> listOf(DokkaVersionType.Release)
}
companion object {
@@ -24,12 +42,14 @@ internal enum class DokkaPublicationChannel {
"bintray-kotlin-dev" -> BintrayKotlinDev
"bintray-kotlin-eap" -> BintrayKotlinEap
"bintray-kotlin-dokka" -> BintrayKotlinDokka
+ "maven-central-release" -> MavenCentral
+ "maven-central-snapshot" -> MavenCentralSnapshot
else -> throw IllegalArgumentException("Unknown dokka_publication_channel=$value")
}
}
}
-internal val Project.publicationChannels: Set<DokkaPublicationChannel>
+val Project.publicationChannels: Set<DokkaPublicationChannel>
get() {
val publicationChannel = this.properties["dokka_publication_channel"]?.toString()
val publicationChannels = this.properties["dokka_publication_channels"]?.toString()
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
index 2a5c21a7..05585d06 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
@@ -24,3 +24,6 @@ private fun dokkaVersionFromBase(baseVersion: String): String {
val Project.dokkaVersion: String
get() = configureDokkaVersion()
+
+val Project.dokkaVersionType: DokkaVersionType?
+ get() = DokkaVersionType.values().find { it.suffix.matches(dokkaVersion.substringAfter("-", "")) }
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt
new file mode 100644
index 00000000..dbf2d312
--- /dev/null
+++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt
@@ -0,0 +1,5 @@
+package org.jetbrains
+
+enum class DokkaVersionType(val suffix: Regex) {
+ Release("^$".toRegex()), Snapshot("SNAPSHOT".toRegex()), Dev("dev-\\d+".toRegex()), MC("mc-\\d+".toRegex())
+}
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt
index 4659f669..4b97d74a 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt
@@ -19,7 +19,7 @@ open class ValidatePublications : DefaultTask() {
class UnpublishedProjectDependencyException(
project: Project, dependencyProject: Project
) : GradleException(
- "Published project ${project.path} cannot depend on unpublished projed ${dependencyProject.path}"
+ "Published project ${project.path} cannot depend on unpublished project ${dependencyProject.path}"
)
@@ -36,6 +36,7 @@ open class ValidatePublications : DefaultTask() {
checkPublicationIsConfiguredForBintray(subProject, publication)
}
checkProjectDependenciesArePublished(subProject)
+ subProject.assertPublicationVersion()
}
}
}
@@ -72,6 +73,19 @@ open class ValidatePublications : DefaultTask() {
}
}
+ private fun Project.assertPublicationVersion() {
+ if (System.getenv("SKIP_VERSION_CHECK")?.contains("true", ignoreCase = true) == true)
+ return
+
+ if (!publicationChannels.all { publicationChannel ->
+ publicationChannel.acceptedDokkaVersionTypes.any { acceptedVersionType ->
+ acceptedVersionType == dokkaVersionType
+ }
+ }) {
+ throw AssertionError("Wrong version $dokkaVersion for configured publication channels $publicationChannels")
+ }
+ }
+
init {
group = "verification"
project.tasks.named("check") {
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt
index 82102467..bb4f3ad3 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt
@@ -4,13 +4,13 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.jfrog.bintray.gradle.BintrayExtension
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.Project
-import org.gradle.api.provider.Provider
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.DokkaPublicationChannel.*
+import io.github.gradlenexus.publishplugin.NexusPublishExtension
import java.net.URI
class DokkaPublicationBuilder {
@@ -26,24 +26,25 @@ class DokkaPublicationBuilder {
fun Project.registerDokkaArtifactPublication(publicationName: String, configure: DokkaPublicationBuilder.() -> Unit) {
configure<PublishingExtension> {
publications {
- val publicationProvider = register<MavenPublication>(publicationName) {
+ register<MavenPublication>(publicationName) {
val builder = DokkaPublicationBuilder().apply(configure)
artifactId = builder.artifactId
when (builder.component) {
DokkaPublicationBuilder.Component.Java -> from(components["java"])
DokkaPublicationBuilder.Component.Shadow -> run {
- artifact(tasks["sourcesJar"])
extensions.getByType(ShadowExtension::class.java).component(this)
+ artifact(tasks["sourcesJar"])
}
}
+ artifact(tasks["javadocJar"])
configurePom("Dokka ${project.name}")
}
- signPublicationIfKeyPresent(publicationProvider)
}
}
configureBintrayPublicationIfNecessary(publicationName)
configureSpacePublicationIfNecessary(publicationName)
+ configureSonatypePublicationIfNecessary(publicationName)
createDokkaPublishTaskIfNecessary()
registerBinaryCompatibilityCheck(publicationName)
}
@@ -83,6 +84,11 @@ fun Project.createDokkaPublishTaskIfNecessary() {
if (publicationChannels.any { it.isSpaceRepository }) {
dependsOn(tasks.named("publish"))
}
+
+ if (publicationChannels.any { it.isMavenRepository }) {
+ dependsOn(tasks.named("publishToSonatype"))
+ }
+
if (publicationChannels.any { it.isBintrayRepository }) {
dependsOn(tasks.named("bintrayUpload"))
}
@@ -110,7 +116,7 @@ private fun Project.configureBintrayPublication(vararg publications: String) {
}
repo = when (bintrayPublicationChannels.single()) {
- SpaceDokkaDev -> throw IllegalStateException("$SpaceDokkaDev is not a bintray repository")
+ SpaceDokkaDev, MavenCentral, MavenCentralSnapshot -> throw IllegalStateException("${bintrayPublicationChannels.single()} is not a bintray repository")
BintrayKotlinDev -> "kotlin-dev"
BintrayKotlinEap -> "kotlin-eap"
BintrayKotlinDokka -> "dokka"
@@ -129,8 +135,13 @@ private fun Project.configureBintrayPublication(vararg publications: String) {
}
}
+fun Project.configureSonatypePublicationIfNecessary(vararg publications: String) {
+ if (publicationChannels.any { it.isMavenRepository }) {
+ signPublicationsIfKeyPresent(*publications)
+ }
+}
-private fun MavenPublication.configurePom(projectName: String) {
+fun MavenPublication.configurePom(projectName: String) {
pom {
name.set(projectName)
description.set("Dokka is a documentation engine for Kotlin and Java, performing the same function as Javadoc for Java")
@@ -161,14 +172,23 @@ private fun MavenPublication.configurePom(projectName: String) {
}
@Suppress("UnstableApiUsage")
-private fun Project.signPublicationIfKeyPresent(publicationProvider: Provider<MavenPublication>) {
- val signingKey = System.getenv("SIGN_KEY")
- val signingKeyPassphrase = System.getenv("SIGN_KEY_PASSPHRASE")
+private fun Project.signPublicationsIfKeyPresent(vararg publications: String) {
+ val signingKeyId: String? = System.getenv("SIGN_KEY_ID")
+ val signingKey: String? = System.getenv("SIGN_KEY")
+ val signingKeyPassphrase: String? = System.getenv("SIGN_KEY_PASSPHRASE")
if (!signingKey.isNullOrBlank()) {
extensions.configure<SigningExtension>("signing") {
- useInMemoryPgpKeys(signingKey, signingKeyPassphrase)
- sign(publicationProvider.get())
+ if (signingKeyId?.isNotBlank() == true) {
+ useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassphrase)
+ } else {
+ useInMemoryPgpKeys(signingKey, signingKeyPassphrase)
+ }
+ publications.forEach { publicationName ->
+ extensions.findByType(PublishingExtension::class)!!.publications.findByName(publicationName)?.let {
+ sign(it)
+ }
+ }
}
}
}
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/taskUtils.kt b/buildSrc/src/main/kotlin/org/jetbrains/taskUtils.kt
index ef9c5e6a..261d1663 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/taskUtils.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/taskUtils.kt
@@ -1,5 +1,6 @@
package org.jetbrains
+import org.gradle.api.Project
import org.gradle.api.Task
fun Task.dependsOnMavenLocalPublication() {
@@ -11,3 +12,11 @@ fun Task.dependsOnMavenLocalPublication() {
}
}
}
+
+val Project.isLocalPublication: Boolean
+ get() = gradle.startParameter.taskNames.any {
+ it.endsWith("publishToMavenLocal", ignoreCase = true) ||
+ it.endsWith("integrationTest", ignoreCase = true) ||
+ it.endsWith("check", ignoreCase = true) ||
+ it.endsWith("test", ignoreCase = true)
+ }