Skip to content

Commit

Permalink
Add OSSRH repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
kamildoleglo committed Jan 20, 2021
1 parent 1f592a7 commit 1d74704
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
6 changes: 1 addition & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ subprojects {
outputDirectory.set(file(dokkaOutputDir))
}

val deleteDokkaOutputDir by registering(Delete::class) {
delete(dokkaOutputDir)
}

register<Jar>("javadocJar") {
dependsOn(deleteDokkaOutputDir, dokkaHtml)
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaOutputDir)
}
Expand Down
14 changes: 12 additions & 2 deletions buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ internal 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
}

companion object {
Expand All @@ -24,6 +32,8 @@ 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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)


Expand Down
52 changes: 39 additions & 13 deletions buildSrc/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package org.jetbrains
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.jfrog.bintray.gradle.BintrayExtension
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.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.DokkaPublicationChannel.*
import java.net.URI
Expand All @@ -28,24 +24,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()
}

Expand Down Expand Up @@ -81,7 +78,7 @@ fun Project.configureSpacePublicationIfNecessary(vararg publications: String) {

fun Project.createDokkaPublishTaskIfNecessary() {
tasks.maybeCreate("dokkaPublish").run {
if (publicationChannels.any { it.isSpaceRepository }) {
if (publicationChannels.any { it.isSpaceRepository } || publicationChannels.any { it.isMavenRepository }) {
dependsOn(tasks.named("publish"))
}
if (publicationChannels.any { it.isBintrayRepository }) {
Expand Down Expand Up @@ -111,7 +108,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"
Expand All @@ -130,6 +127,30 @@ private fun Project.configureBintrayPublication(vararg publications: String) {
}
}

fun Project.configureSonatypePublicationIfNecessary(vararg publications: String) {
if (publicationChannels.any { it.isMavenRepository }) {
configureSonatypePublication(*publications)
signPublicationsIfKeyPresent(*publications)
}
}

private fun Project.configureSonatypePublication(vararg publications: String) {
configure<PublishingExtension> {
repositories {
maven {
if (MavenCentral in publicationChannels) {
url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
} else if (MavenCentralSnapshot in publicationChannels) {
url = URI("https://oss.sonatype.org/content/repositories/snapshots/")
}
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
}
}

private fun MavenPublication.configurePom(projectName: String) {
pom {
Expand Down Expand Up @@ -162,14 +183,19 @@ private fun MavenPublication.configurePom(projectName: String) {
}

@Suppress("UnstableApiUsage")
private fun Project.signPublicationIfKeyPresent(publicationProvider: Provider<MavenPublication>) {
private fun Project.signPublicationsIfKeyPresent(vararg publications: String) {
val signingKeyId = System.getenv("SIGN_KEY_ID")
val signingKey = System.getenv("SIGN_KEY")
val signingKeyPassphrase = System.getenv("SIGN_KEY_PASSPHRASE")

if (!signingKey.isNullOrBlank()) {
extensions.configure<SigningExtension>("signing") {
useInMemoryPgpKeys(signingKey, signingKeyPassphrase)
sign(publicationProvider.get())
useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassphrase)
publications.forEach { publicationName ->
extensions.findByType(PublishingExtension::class)!!.publications.findByName(publicationName)?.let {
sign(it)
}
}
}
}
}
22 changes: 9 additions & 13 deletions runners/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import org.jetbrains.configureBintrayPublicationIfNecessary
import org.jetbrains.configureSpacePublicationIfNecessary
import org.jetbrains.createDokkaPublishTaskIfNecessary
import org.jetbrains.dokkaVersion
import org.jetbrains.*

plugins {
`java-gradle-plugin`
id("com.gradle.plugin-publish") version "0.10.1"
id("com.gradle.plugin-publish") version "0.12.0"
}

repositories {
Expand Down Expand Up @@ -43,6 +40,8 @@ gradlePlugin {
plugins {
create("dokkaGradlePlugin") {
id = "org.jetbrains.dokka"
displayName = "Dokka plugin"
description = "Dokka, the Kotlin documentation tool"
implementationClass = "org.jetbrains.dokka.gradle.DokkaPlugin"
version = dokkaVersion
}
Expand All @@ -52,14 +51,7 @@ gradlePlugin {
pluginBundle {
website = "https://www.kotlinlang.org/"
vcsUrl = "https://github.com/kotlin/dokka.git"
description = "Dokka, the Kotlin documentation tool"
tags = listOf("dokka", "kotlin", "kdoc", "android")

plugins {
getByName("dokkaGradlePlugin") {
displayName = "Dokka plugin"
}
}
tags = listOf("dokka", "kotlin", "kdoc", "android", "documentation")

mavenCoordinates {
groupId = "org.jetbrains.dokka"
Expand All @@ -81,8 +73,12 @@ publishing {
}
}

tasks.withType<PublishToMavenRepository>().configureEach {
onlyIf { publication != publishing.publications["dokkaGradlePluginForIntegrationTests"] }
}

configureSpacePublicationIfNecessary("dokkaGradlePluginPluginMarkerMaven", "pluginMaven")
configureBintrayPublicationIfNecessary("dokkaGradlePluginPluginMarkerMaven", "pluginMaven")
configureSonatypePublicationIfNecessary("dokkaGradlePluginPluginMarkerMaven", "pluginMaven")
createDokkaPublishTaskIfNecessary()

0 comments on commit 1d74704

Please sign in to comment.