Skip to content

Commit

Permalink
Setup publishing to multiple repositories (gradle-plugin publishing i…
Browse files Browse the repository at this point in the history
…s not supported yet)
  • Loading branch information
whyoleg committed Oct 19, 2023
1 parent 73ba7bb commit 07dbe69
Show file tree
Hide file tree
Showing 29 changed files with 305 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.conventions

plugins {
`maven-publish`
signing
}

// TODO: recheck ENV variables - may be replace them with dokka specific renaming to DOKKA_*

publishing {
repositories {
maven {
name = "mavenCentral"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
// TODO: recheck credentials
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
maven {
// TODO: recheck if we need it at all
name = "snapshot"
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
maven {
name = "spaceDev"
url = uri("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
credentials {
username = System.getenv("SPACE_PACKAGES_USER")
password = System.getenv("SPACE_PACKAGES_SECRET")
}
}
maven {
name = "spaceTest"
url = uri("https://maven.pkg.jetbrains.space/kotlin/p/dokka/test")
credentials {
// TODO: should it be different credentials from dev?
username = System.getenv("SPACE_PACKAGES_USER")
password = System.getenv("SPACE_PACKAGES_SECRET")
}
}
// Publish to a project-local Maven directory, for verification. To test, run:
// ./gradlew publishAllPublicationsToProjectLocalRepository
// and check $rootDir/build/maven-project-local
maven {
name = "projectLocal"
url = uri(rootProject.layout.buildDirectory.dir("maven-project-local"))
}
}

publications.withType<MavenPublication>().configureEach {
pom {
name.convention("Dokka ${project.name}")
description.convention("Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java")
url.convention("https://github.com/Kotlin/dokka")

licenses {
license {
name.convention("The Apache Software License, Version 2.0")
url.convention("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.convention("repo")
}
}

developers {
developer {
id.convention("JetBrains")
name.convention("JetBrains Team")
organization.convention("JetBrains")
organizationUrl.convention("https://www.jetbrains.com")
}
}

scm {
connection.convention("scm:git:git://github.com/Kotlin/dokka.git")
url.convention("https://github.com/Kotlin/dokka/tree/master")
}
}
}
}

signing {
useInMemoryPgpKeys(
System.getenv("SIGN_KEY_ID")?.takeIf(String::isNotBlank),
System.getenv("SIGN_KEY")?.takeIf(String::isNotBlank),
System.getenv("SIGN_KEY_PASSPHRASE")?.takeIf(String::isNotBlank),
)
sign(publishing.publications)
setRequired(provider { !project.version.toString().endsWith("-SNAPSHOT") })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.conventions

import org.gradle.jvm.tasks.Jar
import org.jetbrains.MAVEN_PUBLICATION_NAME

plugins {
id("org.jetbrains.conventions.publishing-base")
}

val javadocJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveClassifier.set("javadoc")
// TODO: decide if we really need dokka html in javadoc jar
// description = "Assembles a Javadoc JAR using Dokka HTML"
// from(tasks.dokkaHtml)
}

publishing.publications.register<MavenPublication>(MAVEN_PUBLICATION_NAME) {
artifact(javadocJar)
from(components["java"])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.conventions

plugins {
id("org.jetbrains.conventions.publishing-base")
// TODO: gradle-publish-plugin
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.conventions

import org.gradle.jvm.tasks.Jar
import org.jetbrains.MAVEN_PUBLICATION_NAME

plugins {
id("org.jetbrains.conventions.publishing-base")
id("com.github.johnrengelman.shadow")
}

val javadocJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveClassifier.set("javadoc")
// TODO: decide if we really need dokka html in javadoc jar
// description = "Assembles a Javadoc JAR using Dokka HTML"
// from(tasks.dokkaHtml)
}

publishing.publications.register<MavenPublication>(MAVEN_PUBLICATION_NAME) {
artifact(javadocJar)
shadow.component(this)
artifact(tasks["sourcesJar"])
}

// Manually disable publication of Shadow elements https://github.com/johnrengelman/shadow/issues/651#issue-839148311
// This is done to preserve compatibility and have the same behavior as previous versions of Dokka.
// For more details, see https://github.com/Kotlin/dokka/pull/2704#issuecomment-1499517930
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() }

// TODO: recheck, may be it's not needed as we remove shadowRuntimeElements?
// TODO: configure it here
//tasks {
// // There are several reasons for shadowing all dependencies in one place:
// // 1. Some of the artifacts Dokka depends on, like com.jetbrains.intellij.java:java-psi, are not
// // published to Maven Central, so the users would need to add custom repositories to their build scripts.
// // 2. There are many intertwining transitive dependencies of different versions, as well as direct copy-paste,
// // that can lead to runtime errors due to classpath conflicts, so it's best to let Gradle take care of
// // dependency resolution, and then pack everything into a single jar in a single place that can be tuned.
// // 3. The compiler and ide modules are internal details that are likely to change, so packing everything into
// // a single jar provides some stability for the CLI users, while not exposing too many internals. Publishing
// // the compiler, ide and other subprojects separately would make it difficult to refactor the project structure.
// shadowJar {
// val dokka_version: String by project
//
// // cannot be named exactly like the artifact (i.e analysis-kotlin-descriptors-VER.jar),
// // otherwise leads to obscure test failures when run via CLI, but not via IJ
// archiveFileName.set("analysis-kotlin-descriptors-all-$dokka_version.jar")
// archiveClassifier.set("")
//
// // service files are merged to make sure all Dokka plugins
// // from the dependencies are loaded, and not just a single one.
// mergeServiceFiles()
// }
//}
20 changes: 0 additions & 20 deletions build-logic/src/main/kotlin/org/jetbrains/projectUtils.kt

This file was deleted.

11 changes: 11 additions & 0 deletions build-logic/src/main/kotlin/org/jetbrains/properties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains

import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory

fun ProviderFactory.dokkaProperty(name: String): Provider<String> =
gradleProperty("org.jetbrains.dokka.$name")
27 changes: 6 additions & 21 deletions build-logic/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

package org.jetbrains

import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType

class DokkaPublicationBuilder {
enum class Component {
Expand All @@ -22,24 +19,12 @@ class DokkaPublicationBuilder {
var component: Component = Component.Java
}

internal const val MAVEN_PUBLICATION_NAME = "jvm"

fun Project.registerDokkaArtifactPublication(
publicationName: String,
configure: DokkaPublicationBuilder.() -> Unit
) {
configure<PublishingExtension> {
publications {
register<MavenPublication>(publicationName) {
val builder = DokkaPublicationBuilder().apply(configure)
artifactId = builder.artifactId
when (builder.component) {
DokkaPublicationBuilder.Component.Java -> from(components["java"])
DokkaPublicationBuilder.Component.Shadow -> run {
extensions.getByType<ShadowExtension>().component(this)
artifact(tasks["sourcesJar"])
}
}
}
fun Project.overridePublicationArtifactId(artifactId: String) {
extensions.configure<PublishingExtension> {
publications.withType<MavenPublication>().named(MAVEN_PUBLICATION_NAME) {
this.artifactId = artifactId
}
}
}
17 changes: 5 additions & 12 deletions dokka-runners/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.DokkaPublicationBuilder.Component.Shadow
import org.jetbrains.registerDokkaArtifactPublication
import org.jetbrains.overridePublicationArtifactId

plugins {
id("org.jetbrains.conventions.kotlin-jvm")
id("org.jetbrains.conventions.maven-publish")

// TODO [structure-refactoring] this plugin should not contain the version, it's declared in build-logic
// for some reason, it doesn't want to be resolved without the version, even though it works in other subprojects
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jetbrains.conventions.publishing-shadow")
}

overridePublicationArtifactId("dokka-cli")

dependencies {
implementation("org.jetbrains.dokka:dokka-core")
implementation(libs.kotlinx.cli)
Expand All @@ -22,6 +19,7 @@ dependencies {
}

tasks {
// TODO [structure-refactoring] move to `publishing-shadow` (except Main-Class)
shadowJar {
val dokka_version: String by project
archiveFileName.set("dokka-cli-$dokka_version.jar")
Expand All @@ -31,8 +29,3 @@ tasks {
}
}
}

registerDokkaArtifactPublication("dokkaCli") {
artifactId = "dokka-cli"
component = Shadow
}
10 changes: 4 additions & 6 deletions dokka-runners/maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.registerDokkaArtifactPublication
import org.jetbrains.overridePublicationArtifactId

plugins {
id("org.jetbrains.conventions.kotlin-jvm")
id("org.jetbrains.conventions.maven-publish")
id("org.jetbrains.conventions.publishing-default")
id("org.jetbrains.conventions.maven-cli-setup")
}

overridePublicationArtifactId("dokka-maven-plugin")

dependencies {
implementation("org.jetbrains.dokka:dokka-core")

Expand Down Expand Up @@ -132,7 +134,3 @@ tasks.jar {
})
}
}

registerDokkaArtifactPublication("dokkaMavenPlugin") {
artifactId = "dokka-maven-plugin"
}
10 changes: 4 additions & 6 deletions dokka-subprojects/analysis-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.registerDokkaArtifactPublication
import org.jetbrains.overridePublicationArtifactId

plugins {
id("org.jetbrains.conventions.kotlin-jvm")
id("org.jetbrains.conventions.maven-publish")
id("org.jetbrains.conventions.publishing-default")
}

overridePublicationArtifactId("analysis-kotlin-api")

dependencies {
compileOnly(projects.dokkaCore)
}

registerDokkaArtifactPublication("analysisKotlinApi") {
artifactId = "analysis-kotlin-api"
}
Loading

0 comments on commit 07dbe69

Please sign in to comment.